SQL Server – Identifying Users with SQL Login

authenticationloginssql serversql-server-2008-r2users

Is it possible to find out who used a SQL-Server login?

Let's assume we suspect a person to abuse a SQL login that is supposed to be used by an application only to logon to SQL-Server. Is the domain user who used the SQL login logged anywhere, so that we can make a conclusion who used it?

Best Answer

You can use DMVs to see who's logged in at the time, but this won't get you any historic information.

SELECT c.session_id AS spid, c.auth_scheme, s.login_name,
       s.[host_name], c.client_net_address
FROM sys.dm_exec_connections AS c
INNER JOIN sys.dm_exec_sessions AS s ON c.session_id=s.session_id;

I suppose you could use this code in a logon trigger and save the information to a table, but if you need a running log, you may want to look at Extended Events or running a trace (SQL Server Profiler).