So far, I have written many blogs and I still feel that there are many errors and scenarios which are still uncovered. Whenever I see a new error and find a new solution, I always share it via this blog. Let us see how we can fix errors related to sp_xp_cmdshell_proxy_account.
One of my clients was using below blogs to use proxy to run xp_cmdshell.
SQL SERVER – Enable xp_cmdshell using sp_configure
They informed that they are getting errors while using sp_xp_cmdshell_proxy_account. Here is the first error:
Msg 15137, Level 16, State 1, Procedure sp_xp_cmdshell_proxy_account, Line 1 [Batch Start Line 5]
An error occurred during the execution of sp_xp_cmdshell_proxy_account. Possible reasons: the provided account was invalid or the ‘##xp_cmdshell_proxy_account##’ credential could not be created. Error code: 1326(The user name or password is incorrect.), Error Status: 0.
I was able to reproduce the error by running below (i.e. by giving wrong password)
EXEC sp_xp_cmdshell_proxy_account 'domain\user', 'WrongPassword'
Now, I have given the right password as below
EXEC sp_xp_cmdshell_proxy_account 'domain\user', 'RightPassword'
But got below error.
Msg 15137, Level 16, State 1, Procedure sp_xp_cmdshell_proxy_account, Line 1 [Batch Start Line 6]
An error occurred during the execution of sp_xp_cmdshell_proxy_account. Possible reasons: the provided account was invalid or the ‘##xp_cmdshell_proxy_account##’ credential could not be created. Error code: 5(Access is denied.), Error Status: 0.
WORKAROUND/SOLUTION
In both errors above, even though error message is the same, the Error Code is different. First one has 1326 which was due to incorrect password. The second one has error code of 5, which means access denied. To fix this error, I should launch SSMS as Run as Administrator as shown below.
The above image is taken from the Windows 2016 Operating system, start menu. You might have a different interface, but you get an idea.
Let me know what you think of this blog post by leaving comments below.
Reference: Pinal Dave (https://blog.sqlauthority.com)
5 Comments. Leave new
Thanks for the tip. It was very useful for me.
This did not work for me. I have a SSRS report with calls a stored procedure which calls xp_cmdshell to create an output file on a file share. When the report runs from a scheduled report, it runs fine, but when running it on-demand from the Reporting Server site, it fails on the calls to xp_cmdshell,
I found my problem – It was in fact a bad password with creating the proxy! (after looking at it I don’t know how many times!)
Even after running as Administrator and logged in with sa user, I was still getting the same error 5 (Access Denied). To resolve the issue, I had to connect with the domain user (in my case, its the same one, which will be used for proxy account to execute command shell) and then run the script and it worked.
Thanks.
The below error message can also occur when trying to run EXEC sp_xp_cmdshell_proxy_account if the Windows proxy user account is locked out.
Msg 15137, Level 16, State 1, Procedure sp_xp_cmdshell_proxy_account, Line 1 [Batch Start Line 35]
An error occurred during the execution of sp_xp_cmdshell_proxy_account. Possible reasons: the provided account was invalid or the ‘##xp_cmdshell_proxy_account##’ credential could not be created. Error code: 1909(The referenced account is currently locked out and may not be logged on to.), Error Status: 0.