How many connections are accessing a particular database ?

Posted by PandianS under Sql Server category on | Points: 40 | Views : 2210
SELECT DB_NAME(D.database_id) 'Database',COUNT(1) 'Connection(s)',
(SELECT CAST(spid AS VARCHAR) + ',' FROM sys.sysprocesses WHERE [dbid] = D.database_id FOR XML PATH('')) 'Used Session(s)'
FROM sys.databases D JOIN sys.sysprocesses P
ON(D.database_id = P.[dbid])
WHERE D.[name]= 'DotNetFunda'
GROUP BY D.database_id
Here we have used 'DotNetFunda' as a Database name.

Database Connection(s) Used Session(s)
------------ -------------------- ---------------------
DotNetFunda 2 54,57,

Comments or Responses

Login to post response