Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Domain users connected to SQL database

Status
Not open for further replies.

DougNaf

Programmer
Jun 2, 2005
32
US
I have a need to view domain users that are connected to an SQL Database. I know you can query and display number of users connected, but I would like to know the users.


Thanks in advance for suggestions!
Doug
 
Code:
SELECT l.name 
FROM sys.sysprocesses p JOIN [YOURDATABASENAME]..sysusers u ON p.uid=u.uid left outer 
JOIN master..syslogins l ON u.sid=l.sid  
WHERE dbid = db_Id('YOURDATABASENAME')  
and  len(l.sid)>16 
and l.status!=10
--(sid's that reference domain logins are over 16 in length.. 16 is a sql login. You could also look for the backslash in the name field of the syslogins table.
Bottom line.. the query is not perfect, but it should be enough to get you going
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top