Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get the user name for the loged in user in Windows 3

Status
Not open for further replies.

Mehdi6002

Programmer
Apr 12, 2007
3
EU
Hi Guys,

How can I get the current loged in UserName in windows in MSSQL?

The problem is:

Users login into their PC (Windows Login)
Enter a URL of the intranet application
They would then be able to access the web base application (Intranet)
The web application has a string connection to make a connection to the database
I want to have a Trigger for my "products" table so if the table is modified (Insert/Update) all those changes be entered in "products_Audit" table
Now on "products_Audit" table I have a field "ChangedBy" where I want to store the windows loged in User Name (SYSTEM_USER just return the Username for the SQL connection that the web application use)
I would really appreciate all your help and suggestions.

Regards,
Mehdi
 
I think you will need to pass the user name in from your front end app. Do you have logins on it, or use Windows Authentication?

Hope this helps,

Alex

Ignorance of certain subjects is a great part of wisdom
 
It depends on your connection string and authentication of course but I believe you're looking for
Code:
suser_sname()

msdn

Please read the link carefully for all considerations of usage

____________ signature below ______________
The worst mistake you'll ever make is to do something simply the way you know how while ignoring the way it should be done
 
this may help:

--Following will show you whos logged on to that terminal:

Declare @cmd_query nvarchar(4000)
Declare @computername nvarchar(4000)

select @computername = 'yourcomputername'
select @cmd_query = 'nbtstat -a ' + @computername

exec xp_cmdshell @cmd_query
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top