3

I know that SqlContext.WindowsIdentity returns the current user that is executing the command (in a CLR trigger), however, this only works for windows authenticated users. How do I get the username if it's a sql server user instead? Any help is appreciated.

3 Answers 3

11

Try using SUSER_NAME() function in SQL server. This will return the current user.

Sign up to request clarification or add additional context in comments.

Comments

5

Try using SYSTEM_USER.

SELECT SYSTEM_USER

Comments

0

You can use context of the current connection and get all you need from the connection object.

Like this (in C#):

SqlConnection connection = new SqlConnection("context connection=true");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.