< Back

Exit-DbTransaction

Mon Jan 13, 2020 6:24 pm

NAME Exit-DbTransaction



SYNOPSIS

Exit a SQL transaction.





SYNTAX

Exit-DbTransaction [-InputObject] <Object> [-Commit] [-Rollback] [-PassThru] [<CommonParameters>]





DESCRIPTION

Commit or rollback a SQL transaction.





PARAMETERS

-InputObject <Object>

A SqlCommand with a SqlConnection and SqlTransaction. This can be extracted from a DataTable or a DataSet, but

not a DataRow.



Required? true

Position? 1

Default value

Accept pipeline input? true (ByValue)

Accept wildcard characters? false



-Commit [<SwitchParameter>]

Commit the transaction.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-Rollback [<SwitchParameter>]

Rollback the transaction.



Required? false

Position? named

Default value False

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 SqlCommand or a DataSet. You cannot pipe in a DataTable because it will be enumerated into DataRows.





OUTPUTS

(Optionally) Whatever was piped in.





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



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



$dbData = New-DbConnection $serverInstance | New-DbCommand "Select @@Trancount"

$dbData | Get-DbData -As Scalar

$dbData | Enter-DbTransaction "ABC"

$dbData | Get-DbData -As Scalar

$dbData | Exit-DbTransaction -Commit

$dbData | Get-DbData -As Scalar



Results:

0

1

0



Show the transaction count, begin a transaction and show the transaction count increased. Then rollback and show

the transaction count decreased.











RELATED LINKS