Share via


SQL Query to Check Number of Connections on Database

With the following queries you can check all connections opened for all the databases. If you want to see db connections to specific database you can add an additional where condition for the specific db_id you want to look for.

Query 1:

SELECT DB_NAME(dbid) as DBName, 
       COUNT(dbid) as  NumberOfConnections       
FROM sys.sysprocesses 
WHERE dbid > 0 
GROUP BY  dbid, loginame

Query 2:

select a.dbid,b.name, count(a.dbid) as  TotalConnections
from sys.sysprocesses a 
inner join sys.databases b on  a.dbid = b.database_id
group by  a.dbid, b.name

See Also