Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine what user called my stored procedure

I'm sure this has been asked, but search isn't returning the answer.

In a stored procedure, how do I get the value of the user/login that called the stored procedure (name?), assuming I don't already have server_user_id

like image 233
Russell Steen Avatar asked Dec 31 '25 04:12

Russell Steen


1 Answers

in sql 2005

select suser_name()

http://msdn.microsoft.com/en-us/library/ms187934.aspx

SUSER_NAME ( [ server_user_id ] ) server_user_id

Is the login identification number of the user. server_user_id, which is optional, is int. server_user_id can be the login identification number of any SQL Server login or Microsoft Windows user or group that has permission to connect to an instance of SQL Server. If server_user_id is not specified, the login identification name for the current user is returned.

--

edit: just tried it with Microsoft SQL Server 2008 (SP1) - 10.0.2531.0 (X64)

with integrated and sql security

and all these:

select suser_name()

select suser_sname()

select original_login()

select system_user

correctly return the logged user... I guess there's some problem with your configuration...

saludos

sas

like image 162
opensas Avatar answered Jan 03 '26 14:01

opensas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!