Server.GetActiveDBConnectionCount(String) Server.GetActiveDBConnectionCount(String) Server.GetActiveDBConnectionCount(String) Method

Definition

Returns the number of active connections for the specified database.

public:
 int GetActiveDBConnectionCount(System::String ^ dbName);
public int GetActiveDBConnectionCount (string dbName);
Public Function GetActiveDBConnectionCount (dbName As String) As Integer
Parameters
dbName
String String String

A String value that specifies the name of the database.

Returns

An Int32 value that specifies the number of active connections for the specified database.

Examples

Visual Basic

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

'Display the number active connections to the database.  
Console.WriteLine(srv.GetActiveDBConnectionCount("AdventureWorks2012"))  

PowerShell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")  

Write-Host $srv.GetActiveDBConnectionCount("AdventureWorks2012")  

Remarks

This method returns the number of active connections to a database. By iterating through all the databases on the instance of SQL Server, you can determine the total number of connections to databases on the instance of SQL Server.

Applies to