no of users connected to a database | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

no of users connected to a database

How can i get the number of users connected to a database.
I m using select @@connection but its not giving the desired iutput
@@connections Returns the number of connections, or attempted connections, since SQL Server was last started.
To get the no. of users connected run 1)sp_who
2)sp_who2 either of these two. or else u can try running this….
select * from master..sysprocesses
But this will give information about all the databases in a server.Can you suggest any sp/script which will give the number of users connected to a single database at a particular point of time.
try this———
select db_name(dbid) as DBName,hostname,program_name,login_time,last_batch from master..sysprocesses
where db_name(dbid) =’ur_dbname’ and dbid>0

or select db_name(dbid) as ‘Database’,program_name as ‘Program Name’,count (SPID) as ‘No. of Connections’ from master..sysprocesses
where UPPER(db_name(dbid)) NOT IN (‘MASTER’, ‘MSDB’)
group by db_name(dbid), program_name Satya SKJ
This posting is provided “AS IS” with no rights for the sake of knowledge sharing.