Solved

Finding active Users in SQL

Posted on 2011-09-07
5
218 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL DATEADD 10 81
Check ALL SP in database make sure there are no errors 17 62
GeoClustering  and AOG 25 43
Update one rows based on previous row 5 30
There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 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