< Back

Enter-DbTransaction

Mon Jan 13, 2020 6:24 pm

NAME Enter-DbTransaction



SYNOPSIS

Enter a SQL Transaction.





SYNTAX

Enter-DbTransaction -InputObject <Object> [[-TransactionName] <String>] [-IsolationLevel {Chaos | ReadUncommitted

| ReadCommitted | RepeatableRead | Serializable | Snapshot | Unspecified}] [-PassThru] [<CommonParameters>]





DESCRIPTION

Enter a SQL Transaction.





PARAMETERS

-InputObject <Object>

A SqlCommand with a SqlConnection, or the output of Get-DbData.



Required? true

Position? named

Default value

Accept pipeline input? true (ByValue)

Accept wildcard characters? false



-TransactionName <String>

An optional name for the transaction.



Required? false

Position? 1

Default value

Accept pipeline input? false

Accept wildcard characters? false



-IsolationLevel



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-PassThru [<SwitchParameter>]

Pass the transaction on in the pipeline for further operations.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS

Pipe in the output of New-DbCommand or Get-DbData.





OUTPUTS

(Optionally) Whatever was piped in.





-------------------------- EXAMPLE 1 --------------------------



PS C:\\>$serverInstance = ".\\SQL2016"



$sql = New-DbConnection $serverInstance master | New-DbCommand "Select @@Trancount" | Enter-DbTransaction "ABC"

-PassThru

$sql | Get-DbData -As Scalar

$sql | Exit-DbTransaction -Rollback

$sql | Get-DbData -As Scalar



Results:

1

0



Begin a transaction and show the transaction count increased. Then rollback and show the transaction count

decreased.











RELATED LINKS