xp_cmdshell throws Access is Denied error

  • I have a stored procedure that needs to move a text file from one folder to another when it is finished importing. I have enabled the xp_cmdshell feature through sp_configure.

    Here's my code:

    SET @Command = 'Move \\SCMISC\Test.txt \\SCData\Test_20160716.txt';

    EXEC master.dbo.xp_cmdshell @Command

    It throws Access is Denied error.

    The SQL Server instance is "SCMSQL" on a Windows Server 2012 R2 machine. The logon account is "NT Service\MSSQLSERVER".

    I've tried granting write permission on the from and to folders to User "NT Service\MSSQLSERVER" but that object name isn't recognized by either server. I also tried "\\SCMSQL\NT Service\MSSQLSERVER".

    How do I grant this permission?

  • only a domain account can access server shares, so you'll need to change the service account that SQL is currently running under. NT Service\MSSQLSERVER is not a domain account, so create a mydomain\SQLServiceAccount, grant it access to your specific shares, and your all set.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 2 posts - 1 through 1 (of 1 total)

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