Mcottuli
asked on
Finding active Users in SQL
I have users that sometimes don't log off their PC's and keep a connection to the P21 Program we use. This at times causes us to run out of licenses for users that need to log in. Is there a SQL query I can run against the database to let me know who is actually connected to that particular database? Thanks
If they're using named SQL logins then try exec sp_who or exec sp_who2
ASKER
Is there a way to limit that to a specific database? It seems to bring up all databases within SQL
You could use the dynamic management view sys.dm_exec_sessions.
SELECT login_name, count(session_id) as session_count
FROM sys.dm_exec_sessions
GROUP BY login_name
Greg
SELECT login_name, count(session_id) as session_count
FROM sys.dm_exec_sessions
GROUP BY login_name
Greg
ASKER
Greg Thanks, That one is much cleaner, but again is there a way to bring back results for a specific database, it seems to bring up connections from all databases.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.