1

Dear Stackoverflow users,

I have a SQL Agent Job which generates a specific report in PDF-file and then copies the PDF to a network directory and then deletes the PDF file in the source directory.

The SQL Jobs consists of 2 steps: 1. Generate the report 2. Copy the report to the network location.

For step 2 I made a bat-file which handles the copying and removal of the pdf file.

The bat-file is as follows:

set source_dir=C:\Reports\Energie\Uur
set dest_dir=\\KWS2-WEB-SERVER\Share\Reports\Uur

C:\Windows\System32\Robocopy.exe %source_dir% %dest_dir% /MOV /Z

However, when I run my the Job, it hangs on the second step. The status just stays on "Executing".

This is the line which I stated in the step (location of the bat-file to execute):

cmd.exe /c "C:\Reports\rapport_uur_copy.bat"

My job-settings are as follows:

Step 1

Type: Operating system (CmdExec) On Success: Go to the next step

On Failure: Quit the job reporting failure

Step 2

Type: Operating system (CmdExec)

On Success: Quit the job reporting success

On Failure: Quit the job reporting failure

Some facts:

  • I have read/write permissions on the network directory
  • I run the steps as the Administrator-account (the logged in user, default)
  • Step 1 succeeds
  • I run Windows Server 2008 R2 Standard
  • I have SQL Server 2008 R2
  • When I run the script from the cmd manually, it works (under Administrator account).

Thanks in advance!

3
  • and what happens when you run the batch file directly? it prompts you right? You need to work out the correct switch to stop it prompting. The other reason things don't work from SQL Agent is because the account it runs under is different to your account. For example, by default the SQL Agent account cannot access any network drives even though you can.
    – Nick.Mc
    Mar 4, 2013 at 9:09
  • @ElectricLlama When I run the batch script directly (i.e double click on the file) no prompt appears. It just runs. I run the script as Administrator. I created a proxy named "asAdminProxy" where the Administrator credentials are defined.
    – Nazeem
    Mar 12, 2013 at 8:21
  • Sorry, I see that you already tried running it manually. When the job hangs, can you open up task manager and check that your CMD process is there under the expected credentials? You could try adding the /Log: parameter to log operation (this is a good idea anyway). Just make sure you log to a file that you will definitely have access to. You could also use /v for verbose. You could also use "C:\Reports\rapport_uur_copy.bat" >> C:\Log.TXT to log your batch file to another log.
    – Nick.Mc
    Mar 12, 2013 at 23:00

1 Answer 1

3

when a batch script needs to use drives not local, eg shares it always needs special rights, means you need to use an account to run the script which is allowed to log on as batch task in secpol - (click start type secpol.msc and start it - Select "Local Policies" in MSC snap in - Select "User Rights Assignment" - Right click on "Log on as batch job" and select Properties - Click "Add User or Group", and include the relevant user.)

too in normal batch it is not possible to use \\drives, they have to get mapped as drives with a char e.g. V:\drive and this mapping got to be made by the batch itself with the user account used running the batch i experienced this in a script of mine.

1
  • 1
    @Naz33m not interested anymore?
    – peet
    Nov 23, 2013 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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