Link to home
Start Free TrialLog in
Avatar of Mcottuli
McottuliFlag for United States of America

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
Avatar of Lee
Lee
Flag of United Kingdom of Great Britain and Northern Ireland image

If they're using named SQL logins then try exec sp_who or exec sp_who2
Avatar of Mcottuli

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

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
Avatar of JestersGrind
JestersGrind
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial