I am trying to execute a batch file from SQL Server 2012 JObs with the following command

cmd.exe /c "D:\Batch Files\SQLDBBkupCopy.bat".

The objective of the batch file is to copy SQL DB backup to a different machine in the network. The Job successfully ran, but there was no files copied.

From the Jobs history I could able to see this error message:

Executed as user: SLC\sqlagentservice. Invalid drive specification 0 File(s) copied. Process Exit Code 0. The step succeeded.

Here is my Batch file script:

@echo off
echo.%Date% %Time%:- INITIATING FOLDERS......>>CopyLog.txt
set folder1="B:\SLCBackup\ForSymantec"
set folder2="\\testsvr\c$\SQLBKUP\SLCDBAREN"
echo.%Date% %Time%:- Initiation Complete.....>>CopyLog.txt
echo.%Date% %Time%:- Copying from %folder1% to %folder2% >>CopyLog.txt
xcopy /E /C /R /I /K /Y %folder1% %folder2%
echo.%Date% %Time%:- Complete...>>CopyLog.txt

However, if I try to copy in the same machine like:

set folder2="c:\test1" 

it then works.

  • 1
    A see that the destiny is begin with '\' and not with '\\'. See if the service user of SQL Server has privileges at the destiny folder. – Krismorte Feb 22 '16 at 11:14
  • Hi Kris, thanks for the reply. But i have set this as "set folder2="\\testsvr\c$\SQLBKUP\SLCDBAREN" – Suman Feb 22 '16 at 11:22
  • I see, but the privileges at the destiny folder. Do you see if the SQL user services has it? – Krismorte Feb 22 '16 at 11:23
  • correct, the agent service user does not have permission to the destination machine... let me set and update you. Thanks. – Suman Feb 22 '16 at 11:46
  • Hi Kris, Your Suggestion worked, the agent service user did not have the right to copy. Thanks a lot – Suman Feb 22 '16 at 12:09

For any interaction with the Operation System, insure that the user services of SQL Server has the privileges

| improve this answer | |
  • I have the similar issue now.I have given default network service as the service account.But i am not able to add it to the administor group – sparktech May 16 '18 at 20:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.