how to know how many users are connected to a particular database
views:
161answers:
3
A:
For a simply query, you can use this on SQL 2000 to SQL 2008 (there is no 1:1 replacement for sysprocesses in SQL 2005)
SELECT
COUNT(*)
FROM
MASTER..sysprocesses
WHERE
dbid = DB_ID('MyDBName')
gbn
2009-06-02 09:28:27
I believe this query will get you a wrong count if parallel queries are being executed. You're also not removing the system processes from the result.
LeoPasta
2009-06-02 12:22:41
A:
SELECT COUNT(DISTINCT spid)
FROM master.dbo.sysprocesses
WHERE spid >= 50
AND dbid = DB_ID('MyDBName')
LeoPasta
2009-06-02 12:24:59