I have a question regarding the extended SPC 'xp_cmdshell'.
Basically I want to determine the username and userdomain in a stored procedure and what I know is that you can get this information in a "DOS-Box" with 'Set username' or 'Set userdomain'.
But if I use the above mentioned extended stored procedure in the following way:
exec master..xp_cmdshell 'set username'I don´t get any resultset.
Does anyone know why I get different results depending on the fact if I call the 'set'-command in a "DOS-Box" or with the appropriate stored procedure?
Thank you for any help>>Basically I want to determine the username and userdomain in a stored procedure and what I know is that you can get this information in a "DOS-Box" with 'Set username' or 'Set userdomain'.
You are aware that xp_xmdshell is running in the context of Sql Server. So you will only ever see information pertaining tho the server - not any client.
What user and domain are you trying to retrieve? The client connecting to SQL Server or the Server itself?|||Hello,
yes, you are absolutely right! I am aware of this but I have just tried this on my local machine. I have installed SQL-server local and I was just wondering because of this differences on the same machine. I know that I can´t use this in a production environment because of the fact that this SPC is running in the context of the server and does not affect any client.
What I basically want is to retrieve the domainname and -user of the client connection with a stored procedure.
Do you know a practicable method to do this?
Thanks,|||SQL Server provides several functions for this purpose each with differing behavior. Have a look in SQL Server Books Online at the following keywords for starters:
USER_NAME()
SESSION_USER
USER|||Hello,
thank you for the advice to the functions of sql server. I have looked around now for a while and have found a function which returns indeed the domainname and domainusername of the connected client.
Just beside -- the functions you mentioned just give back the actually sql-server user in the selected database which is in my environment always 'dbo'.
You can get the domaininfo with the following piece of code:DECLARE @.System_User char(30)
Regards,
SET @.System_User=SYSTEM_USER
PRINT @.System_User
No comments:
Post a Comment