Find active SQL Server connections for Database


Sometimes we need to check the connection for the database, using the following query we can get the total connection, login Name with Database Name.

Run below script
SELECT DB_NAME(DBID) AS DataBaseName,
COUNT(DBID) AS TotalConnections,
loginame AS LogName
FROM    sys.sysprocesses
GROUP BY DBID, loginame
ORDER BY DB_NAME(DBID)

The result will be shown below.

DataBaseName                 TotalConnections            LogName
-------------------------------------------------
MYTESTDB                          3                                dkadmin
MYDKDB                             119                             dkadmin
MYDKDB                             10                               sa     
master                                17                              sa    
master                                12                              dkadmin
msdb                                  3                                NT SERVICE\SQLSERVERAGENT
                 

Related Posts

What is the Use of isNaN Function in JavaScript? A Comprehensive Explanation for Effective Input Validation

In the world of JavaScript, input validation is a critical aspect of ensuring that user-provided data is processed correctly. One indispensa...