May 6, 2013 at 9:44 am
Hi,
Is there a way of getting the windows user name using an application accessing SQL Server with SQL Authentication?
The sysprocesses has the hostprocess id but not the windows user that opened it...
With a CLR is possible to write code to get a process id user, but is this also possible with "simple" T-SQL?
Thanks,
Pedro
May 6, 2013 at 9:52 am
You can just run this.
SELECT SYSTEM_USER
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
May 6, 2013 at 10:08 am
Doesn't work. Returns the SQL Authenticated user, not the windows user that opened the application using the process.
Pedro
May 6, 2013 at 10:16 am
nope not from SQL;
you can have the application do it,and pass the user to SQL in the CONTEXTINFO, but once connected via a SQL user, no domain info can be backtracked...at least not directly.
maybe, just maybe, if the user is coming form a LAN/domain and not the web,you could do a round-about to get the HOSTNAME of the machine(if it's not faked!) to get the machine name, and then a CLR to get the user(s) currently logged into that machine, i think;
Sorry i have no sample code to do that, just brainstorming.
Lowell
May 6, 2013 at 10:23 am
PiMané (5/6/2013)
Doesn't work. Returns the SQL Authenticated user, not the windows user that opened the application using the process.Pedro
Oops I misread your original post. I thought you had said using Window Auth. DOH!!!
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
May 6, 2013 at 10:24 am
Lowell (5/6/2013)
nope not from SQL;you can have the application do it,and pass the user to SQL in the CONTEXTINFO, but once connected via a SQL user, no domain info can be backtracked...at least not directly.
maybe, just maybe, if the user is coming form a LAN/domain and not the web,you could do a round-about to get the HOSTNAME of the machine(if it's not faked!) to get the machine name, and then a CLR to get the user(s) currently logged into that machine, i think;
Sorry i have no sample code to do that, just brainstorming.
Thanks, no prob 🙂
I have the c# code for a CLR function that gives the windows user name attached to a windows process.
Just have to write the CLR and use the function with sysprocesses.
Thanks,
Pedro
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply