List active connections to Microsoft SQL Server database.
Via the master.dbo.sysprocesses
system table.
SELECT [hostname],COUNT(*)
FROM master.dbo.sysprocesses
WHERE
([dbid] = db_id('DATABASE_NAME')) AND
([spid] > 50)
GROUP BY [hostname]
ORDER BY 2 DESC
Where spid
is the session ID, greater than 50 are user processes (what we care about).
A listing of database IDs can be returned via:
SELECT [name],[dbid]
FROM master.dbo.sysdatabases