Solved

Finding active Users in SQL

Posted on 2011-09-07
5
204 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 500 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

825 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