SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On



Which logins are being used Expand / Collapse
Author
Message
Posted Wednesday, September 03, 2008 11:05 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, May 24, 2010 1:08 PM
Points: 3, Visits: 36
I would like to audit which logins are being used and then be able to identify and delete the logins that are no longer needed.
I've looked at sysprocesses, sp_who, sp_who2, profiling to find active logins but my problem is that many of the sessions are connecting with Windows authentication which shows up as DOMAIN\Username.
The logins in SQL are a mixture of SQL logins, and Windows logins either DOMAIN\Group or DOMAIN\User.

I can't find a way to link the logins I'm seeing in the above methods to which SQL login is being used for their connection.
Post #563219
Posted Thursday, September 04, 2008 6:41 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Yesterday @ 9:13 PM
Points: 8,605, Visits: 8,787
You can use the default trace that is running on SQL Server 2005, it Audits logins and logouts so you can use the Audit Login event to see the logins that are actually being used. You will still see the Domain\UserName, but if that is what you are seeing that is how they are logging in. Here is a query that gets the data:

SELECT
  
GT.loginname,
  
MIN(GT.StartTime) AS FirstLogin,
  
MAX(GT.StartTime) AS LastLogin
FROM
  
sys.traces T CROSS Apply
  
::fn_trace_gettable(T.path, 5) GT
WHERE
  
GT.loginname IS NOT NULL
GROUP BY
  
GT.LoginName





Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #563743
Posted Thursday, September 04, 2008 8:09 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, September 04, 2008 8:05 AM
Points: 2, Visits: 4
The users will login to SQL server with their windows account Domain\Username but in SQL we may only have windows groups setup (i.e. Domain\Domain Users, Domain\Domain Admins, Domain\Power users, etc.) and I need to know which of these group is being used. I'm trying to find out if I remove for example Domain\Power users group from SQL will I affect any users that may be getting authenticated via this group.
Post #563835
Posted Thursday, September 04, 2008 8:26 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Yesterday @ 9:13 PM
Points: 8,605, Visits: 8,787
I don't think that there is any default way within SQL Server to identify this as the SQL Server itself just knows the User Name not Domain Group that is logged in. After a little experimentation I think I found this query which uses the default trace in SQL Server 2005 to identify logins which are using a Group to access the SQL Server, it DOES NOT show the group, you would have to check AD to determine what group(s) the logins are part of:

SELECT DISTINCT
  
I.NTUserName,
  
I.loginname,
  
I.SessionLoginName,
  
I.databasename,
  
S.*
FROM
  
sys.traces T CROSS Apply
  
::fn_trace_gettable(T.path, 5) I LEFT JOIN
  
sys.syslogins S ON
      
CONVERT(VARBINARY(MAX), I.loginsid) = S.sid    
WHERE
  
S.sid IS NULL






Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #563852
Posted Thursday, September 04, 2008 10:08 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Wednesday, September 01, 2010 4:23 PM
Points: 9,341, Visits: 8,799
Jack Corbett (9/4/2008)
SELECT
  
GT.loginname,
  
MIN(GT.StartTime) AS FirstLogin,
  
MAX(GT.StartTime) AS LastLogin
FROM
  
sys.traces T CROSS Apply
  
::fn_trace_gettable(T.path, 5) GT
WHERE
  
GT.loginname IS NOT NULL
GROUP BY
  
GT.LoginName



This is seriously cool, Jack. I think that I'm going to steal this... :)


-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Post #563964
Posted Thursday, September 04, 2008 10:19 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Yesterday @ 9:13 PM
Points: 8,605, Visits: 8,787
Glad you like it Barry.

I have been doing a lot of research into Profiler and Tracing which is why many of my answers now include using that information.




Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #563975
Posted Friday, September 05, 2008 9:16 AM


UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: Yesterday @ 3:20 AM
Points: 1,446, Visits: 294
Robert Phillips (9/4/2008)
The users will login to SQL server with their windows account Domain\Username but in SQL we may only have windows groups setup (i.e. Domain\Domain Users, Domain\Domain Admins, Domain\Power users, etc.) and I need to know which of these group is being used. I'm trying to find out if I remove for example Domain\Power users group from SQL will I affect any users that may be getting authenticated via this group.


my understanding is that if the domain user is a member of multiple groups, there is no way of knowing which group the user will be a member of when authenticated. this is the reason why you cannot assign a default schema to a windows group, because the user could be in more than one group and therefore would end up with a (possible) different default schema.

we actually had this problem when we assigned default databases to windows groups. every time a person or service account logged into an instance it would be in a different database (or so it seemed).

anyway, i have never seen a way to find out what group the login is a member of, but you would think there should be a system proc that would determine this info. if i find one, i will let you know.


----------------------
http://thomaslarock.com
Post #564694
« Prev Topic | Next Topic »


Permissions Expand / Collapse