Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Windows User

Author  Topic 

gavinjb
Starting Member

34 Posts

Posted - 2010-05-10 : 07:01:50
Hi,

Does anyone know how I can get the UserName that someone is logged onto Windows with (Windows Auth is not being used), I need to store this in an Audit table but cant find anyway of doing this.

Thanks,



Gavin,

gavinjb
Starting Member

34 Posts

Posted - 2010-05-10 : 07:07:34
Update: I am looking for the alternative to doing environ("username") in vb/vba
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2010-05-10 : 07:49:22
SELECT SYSTEM_USER

- Lumbago
If the facts don't fit the theory, change the facts. Albert Einstein
Go to Top of Page

gavinjb
Starting Member

34 Posts

Posted - 2010-05-10 : 10:40:39
Thanks, but that didn't work, it returned the SQL User, while what I am after is the Windows User.

If there isn't an option I could always change my procedure to take an additional input Parameter where the calling app (C#) could pass the Windows User, but it would be easier if I could do it all in SQL Server.

Thanks,



Gavin,
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2010-05-11 : 03:28:17
The SYSTEM_USER will return the user of the current connection (SPID) to the database. The database has no concept of who is connected to an application on another server unless it is passed as a parameter to a query/procedure or the database connection is running under the same context as the application (single sign-on/pass-through authentication). If for example both your database server and your application server is in the same domain it is possible to use trusted authentication which in essense means that the current windows user in the application will be passed as the database user whenever a connection is created.

If you have say a web application where all connections to the database are created with the same sql username/password there is no other option but to pass it as a parameter.

- Lumbago
If the facts don't fit the theory, change the facts. Albert Einstein
Go to Top of Page
   

- Advertisement -