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.
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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.