Get Windows account name of user who's running query

There is a function in SQL Server 2005 that returns the WINDOWS login of the person running a query.
It's not System_user or Current_User or User_Name.

For Windows users connecting to SQL Server with a SQL account, those return the SQL login.

But this application always runs under the account ProgramUser (for example).  But I need to audit whether 'JDoe', 'SSmith' or 'MBrown' is the windows login behind it.

I've used this before but I can't find it today ...

What's the function I'm looking for!

Thanks!
LVL 32
Daniel WilsonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chapmandewCommented:
SUSER_SNAME()
0
Daniel WilsonAuthor Commented:
No, I'm getting the same thing.

Other ideas?
0
chapmandewCommented:
what is your login?  what are you wanting to see?
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

chapmandewCommented:
so, for a sql login, you want to see the MachineName that the connection is made, right?
0
TunerMLSystems EngineerCommented:
suser_sname() was what I thought you were after as well but try original_login()
0
Daniel WilsonAuthor Commented:
Most of the users are connecting to Citrix_Server to run the application.  They are logging into Windows as 'JDoe', 'SSmith', 'MBrown', etc.

But they are all running the application as 'ProgramUser'.

I am connecting to Remote Desktop on DB_Server as 'ApplicationAdmin' and logging into SQL Server via SSMS as 'ProgramManager'.

I want to see the Windows login --  'JDoe', 'SSmith', 'MBrown', 'ApplicationAdmin' -- NOT 'ProgramUser' or 'ProgramManager'.

Thanks!
0
chapmandewCommented:
But, SQL has no idea that those windows logins exist (it doesn't even care..that is why you can use SQL logins from linux machines, etc).  You can look at the HOST_NAME() to see what machine they are connecting from, but you can't determine their windows account, because SQL doesn't know it.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chapmandewCommented:
no, original_login() only matters where there are context switches, such as using EXECUTE AS
0
Daniel WilsonAuthor Commented:
Looks like you're right.  It's when using Windows authentication that those data are available.

Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.