Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 29th, 2005, 08:23 AM
Registered User
 
Join Date: Jan 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Returning NT User Name in SQL 2000

Is there any Extended Stored Procedure or Function that can tell me the NT account logon of a database user if they are logged on the SQL Server with a SQL account. I know it's easy to find this if they have logged on with Windows Authentication.

I know this info can be found in the SQL profiler.

BUT, I need to use this info in a trigger to update/insert a user_id column

Regards

Chris
 
Old January 29th, 2005, 09:37 AM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Default

SYSTEM_USER()

the current user is logged in to Microsoft® SQL Server™ using Windows Authentication, SYSTEM_USER returns the Windows 2000 or Windows NT 4.0 login identification name, for example, DOMAIN\user_login_name. However, if the current user is logged in to SQL Server using SQL Server Authentication, SYSTEM_USER returns the SQL Server login identification name, for example, sa for a user logged in as sa

 
Old January 29th, 2005, 10:41 AM
Registered User
 
Join Date: Jan 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply

Unfortunately users are logged in using SQL Server Authentication - with several users sharing one account. However I really need to know which individual has updated/inserted a record into a table. I was hoping there was some way of finding each user's individual NT login.

 
Old January 29th, 2005, 07:53 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc
Default

try using suser_sname()

Jaime E. Maccou
 
Old January 31st, 2005, 11:08 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 231
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have just tried a quick test using the SYSTEM_USER() and SUSER_SNAME() functions, once logged on as sa and once using Windows Authentication and my domain account, both functions return the same thing, the user I logged on as, so when logged on as sa they both return 'sa' and when logged on using my domain account they return my domain account name.

Unfortunately I do not have any wonderful suggestions of my own I am just reporting on the suggestions of shahchi1 and Jaime. My only suggestion would be to store the logon information in your front end using an API call and pass this value to all the stored procedures that are used to update tables.

Regards
Owain Williams





Similar Threads
Thread Thread Starter Forum Replies Last Post
failed for user 'NT AUTHORITY\NETWORK SERVICE' GS ASP.NET 2.0 Professional 5 March 26th, 2007 05:16 AM
user 'NT AUTHORITY\NETWORK SERVICE' GS ASP.NET 2.0 Basics 0 March 25th, 2007 10:58 AM
SQL Server / Login failed for user 'NT AUTHORITY ElPato ASP.NET 1.0 and 1.1 Basics 2 November 14th, 2004 10:03 AM
How to detect if a user is logon a Windows NT øej Pro VB.NET 2002/2003 1 January 23rd, 2004 10:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.