?
Solved

Finding active Users in SQL

Posted on 2011-09-07
5
Medium Priority
?
241 Views
Last Modified: 2012-08-13
      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
0
Comment
Question by:Mcottuli
  • 2
  • 2
5 Comments
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 36496038
If they're using named SQL logins then try exec sp_who or exec sp_who2
0
 
LVL 1

Author Comment

by:Mcottuli
ID: 36496098
Is there a way to limit that to a specific database? It seems to bring up all databases within SQL
0
 
LVL 21

Expert Comment

by:JestersGrind
ID: 36496296
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

0
 
LVL 1

Author Comment

by:Mcottuli
ID: 36496382
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.
0
 
LVL 21

Accepted Solution

by:
JestersGrind earned 2000 total points
ID: 36498112
Sorry, I sent you my query for listing users and the number of connection to the server.  Try this one.

select spid, loginame, hostname, db_name(dbid) AS DBName
from master.dbo.sysprocesses
where db_name(dbid) = 'YourDatabase'

Greg

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question