Tuesday, February 14, 2012

Determining the number of Active users logged into a SQL Server Database

How does one Determine the number of Active users logged into a SQL Server Database?

I want to use the info to control concurrent licensing for my Application

This query will give you a count grouped by DB, you can also use sp_who or sp_who2

select db_name(dbid),count(*) from master..sysprocesses
where spid > 49 --everyting below 50 is SQL Server itself
group by db_name(dbid)

Denis the SQL Menace

http://sqlservercode.blogspot.com/

|||Thanks, I will. I believe this is exactly what I am looking for. Is it safe to assume that the data is available in "real time"? Also if a user logged in to the DB drops his connection by doing something stupid like powering off his workstation without closing the app first, will the count be reduced, the next time it is run?|||Yes the data is real time, the server connection will disapear once the connection times out or the connection has been removed from the connection pool.

No comments:

Post a Comment