December 12, 2011 at 4:02 am
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
December 12, 2011 at 4:05 am
Assuming I understand you correctly
SELECT SUSER_NAME()
December 12, 2011 at 4:10 am
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
December 12, 2011 at 4:15 am
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?
December 12, 2011 at 4:31 am
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
December 12, 2011 at 4:35 am
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
December 12, 2011 at 6:55 am
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