Solved

Finding active Users in SQL

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now