Database.GetTransactionCount Database.GetTransactionCount Database.GetTransactionCount Method

Definition

Gets the number of open transactions on the database.

Overloads

GetTransactionCount() GetTransactionCount() GetTransactionCount()

Gets the number of open transactions on the database.

GetTransactionCount(TransactionTypes) GetTransactionCount(TransactionTypes) GetTransactionCount(TransactionTypes)

Gets the number of open transactions of a specified type on the database.

GetTransactionCount() GetTransactionCount() GetTransactionCount()

Gets the number of open transactions on the database.

public:
 int GetTransactionCount();
public int GetTransactionCount ();
Public Function GetTransactionCount () As Integer
Returns

An Int32 value that specifies the number of open transactions on the database.

Examples

VB

'Connect to the local, default instance of SQL Server.  
Dim srv As Server  
srv = New Server  

'Reference the AdventureWorks2012 database.  
Dim db As Database  
db = srv.Databases("AdventureWorks2012")  

'Display the number of open transaction on the database.  
Console.WriteLine(db.GetTransactionCount.ToString)  

PowerShell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")  
$db = New-Object Microsoft.SqlServer.Management.Smo.Database  
$db = $srv.Databases.Item("AdventureWorks2012")  

Write-Host $db.GetTransactionCount()  

Remarks

This method is useful when you change the snapshot isolation setting of the database to True, because the call can take a long time when there are long-running open transactions.

GetTransactionCount(TransactionTypes) GetTransactionCount(TransactionTypes) GetTransactionCount(TransactionTypes)

Gets the number of open transactions of a specified type on the database.

public:
 int GetTransactionCount(Microsoft::SqlServer::Management::Smo::TransactionTypes transactionType);
public int GetTransactionCount (Microsoft.SqlServer.Management.Smo.TransactionTypes transactionType);
Public Function GetTransactionCount (transactionType As TransactionTypes) As Integer
Parameters
transactionType
TransactionTypes TransactionTypes TransactionTypes

A TransactionTypes object value that specifies the transaction type of which to limit the returned count.

Returns

An Int32 value that specifies the number of open transactions on the database of the specified type.

Examples

VB

'Connect to the local, default instance of SQL Server.  
Dim srv As Server  
srv = New Server  

'Reference the AdventureWorks2012 database.  
Dim db As Database  
db = srv.Databases("AdventureWorks2012")  

'Display the number of open transaction on the database.  
Console.WriteLine(db.GetTransactionCount.ToString)  

PowerShell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")  
$db = New-Object Microsoft.SqlServer.Management.Smo.Database  
$db = $srv.Databases.Item("AdventureWorks2012")  

Write-Host $db.GetTransactionCount()  

Remarks

You can use this method to determine how many transactions of a specific type are open on the database.

Applies to