By using sp_who2 I can get a list of current log-in users and machine names. Some users are using SQL Server log-in user name such as sa. Is there any way I can get the windows log-in user name for the SQL log-in users?
If there is no way to get Windows log-in users from the machine names, can I use WMI class or C# to get find out the Windows log-in user names by their machine names?
My SQL server is Microsoft SQL Server 2005 and Windows is Server 2003.
There is no link between a SQL login and the NT username.
You asked similar here: How to find out user name and machine name to access to SQL server
The WMI approach will be ambiguous if more than 1 user is logged into the client PC (eg service accounts, remote user via mstsc etc). Any approach like this will require admin rights on the client PC too for the account used.
I doubt you can do it in real time.
All you can do is record the
client_net_addressinsys.dm_exec_connectionsand backtrack from there, perhaps via WMI but not from SQL Server itself.Do you need the username though? Or just the client PC so you can change the app connection string?
You final solution is to change the sa password and see who calls, if you only have relatively few SQL connections