Groups | Blog | Home
all groups > sql server connect > june 2007 >

sql server connect : NT login name


Mikki
6/5/2007 2:14:58 PM
Hi,

I am trying to find the way to identify the name of the Windows NT workstation user using T-SQL in SQL Query Analyzer. Using user_name(), user, SESSION_USER, system_user, etc. gives me current SQL server login name/id;
HOST_NAME(),HOST_id() shows the name of the computer not the username.
Is there is any way of accessing NT Authentication data like username from SQL Query Analyzer if you are logged in with SQL server credentials?
Thanks a lot if anybody can help.

From http://www.developmentnow.com/g/100_2003_11_0_0_0/sql-server-connect.htm

Posted via DevelopmentNow.com Groups
Russell Fields
6/6/2007 9:54:41 AM
Mikki,

If the NT workstation user connects to the SQL Server as himself (a trusted
connection) then system_user (or SUSER_SNAME) should provide the Windows
Login name.

If your user is logging in as a SQL Server account, then system_user will
know him by that account name. In that case, SQL Server does not know the
windows session login name since it has not been 'entrusted' with that
information.

In the second case, since you have the HostName (and in sysprocesses, the
network address) it may be possible to write an Active Directory query to
get that information for you, but aside from setting up an AD linked server,
I do not know enough AD info to know how to query for that. (And AD queries
are slow.)

RLF

[quoted text, click to view]

AddThis Social Bookmark Button