Retriving username ,who is executing the query

  • Hi There,

    I have a requirement of knowing the user who is executing a query/stroed proc.let me be more clear:

    lets say ,we have an application which connects to the sql server and invokes some stored procs(say SP_Temp) on that.now in my Sp_Temp i need to have a T-sql statement which finds out which user is executing this query (assuming the connection string to be using integrated security ,the user name what we get should be the windows user name).could anybody please throw some thoughts on the above.

    Hope i am clear.

    Thanks & Regards

    Deepak

  • SELECT login_name FROM sys.dm_exec_sessions WHERE session_id = @@spid

    Check BOL for both sys.dm_exec_sessions and sys.dm_exec_requests to see what other useful info is available. (host_name, etc.)

    -Eddie

    Eddie Wuerch
    MCM: SQL

  • Are the connections being made via Windows Auth or is your application connecting each user through the same username/password? If so I'd suggest having the application deal with finding which username it is and if it's needed pass it to the sproc as another variable.

    To help us help you read this[/url]For better help with performance problems please read this[/url]

  • Hi ,

    Thanks for your reply ,it was really helpfull. now added to the user information ,i will also be requiring the language info,my requirement is to get the language setting of the user how is querying the database .the sys.dm_exec_sessions do have the "langauge" column and the documentation says " LANGUAGE setting for the session. NULLABLE. " .but this is always US_English .

    i tried few things :

    changed the language settings(client m/c) and queried the DB :the value in the language column is still "US_English"

    changed the language settings(server m/c) and queried the DB :the value in the language column is still "US_English"

    restarted the sql server ,but the results were same .

    the new sessions created was always populating the language column to US_English

    so, any thoughts/help on this will be highly appreciated.

    Thanks & Regards

    Deepak

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply