Return SQL Server service user in T-SQL

  • Hi all

    Is it possible to get the name of the user running the 'current' SQL Server instance in T-SQL?

    I know that pretty much everything is possible, so the question will no doubt become: 'What is the best way to do this?'

    Thanks

    Phil

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Assuming I understand you correctly

    SELECT SUSER_NAME()


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • Thanks, but that returns the current user - not quite what I am after.

    I want the name of the user which is running the SQL Server service for the particular instance on which the query is executing, on the DB server itself.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Phil Parkin (12/12/2011)


    Thanks, but that returns the current user - not quite what I am after.

    I want the name of the user which is running the SQL Server service for the particular instance on which the query is executing, on the DB server itself.

    Ah, so I didn't understand correctly 😀

    I don't think you can return that information with T-SQL (happy to be proven incorrect). I'd guess a CLR may be able to do it, is that an option?


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • Cadavre (12/12/2011)


    Phil Parkin (12/12/2011)


    Thanks, but that returns the current user - not quite what I am after.

    I want the name of the user which is running the SQL Server service for the particular instance on which the query is executing, on the DB server itself.

    Ah, so I didn't understand correctly 😀

    I don't think you can return that information with T-SQL (happy to be proven incorrect). I'd guess a CLR may be able to do it, is that an option?

    Thanks for that - CLR is an option, but overkill in this case. It's just a one-off job and it's easier just to tweak the definition of the proc from one server to another than worry about CLRs.

    --edit I just reread my original post - sorry I wasn't quite specific enough with the question.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • This should do the job:

    http://www.sqldbadiaries.com/2010/10/23/query-to-find-out-service-account-details/

    The query is for the default instance, but is easily adapted for named instances

  • Thank you Howard!

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

Viewing 7 posts - 1 through 6 (of 6 total)

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