0

I am trying to execute a batch file from SQL Server Agent (as it needs to be done before some SSIS-packages are run). When I execute the job it fails in a few seconds saying "Access denied".

The account under which SQL Server Agent runs has full control on the folder that contains the batch file. The result of the batch would be deleting some files in a folder, calling a webservice and get those same files back from the webservice. I can run the batch file when I start it with my own (admin) account.

I googled and found several other questions and answers but none of those were covering my problem. I hope you can point to other options.

Thanks for your help.

Johan

Batch file contents:

echo Removing txt files of last run
del Employees.txt
del HrDepFun.txt
del HrEmpActual.txt
echo Files removed
echo Starting getconnectors
{Call Webservice} -> cannot disclose this on stackoverflow
echo Getconnectors done

Batch file execution statement from SQL Server Agent job (type Operating System (CmdExec)):

cmd.exe /c "c:\Program Files (x86)\AFAS\AFASRemote_Call_GetConnectors.bat" > connectorlog.txt 2> connectorerrorlog.txt
analyzethat
  • 191
  • 1
  • 16
  • 2
    My first guess would be that whatever the batch is trying to delete is something that the account you're running under isn't authorized to delete. – Ann L. Aug 05 '15 at 12:21
  • 1
    Did you mean to say "some folders in a file"? Is it "some files in a folder"? – Ann L. Aug 05 '15 at 12:21
  • 1
    the files and folder are located on the sql server? if not, the script is using UNC paths? some context would be helpful to help you... – Paolo Aug 05 '15 at 12:37
  • @Ann: it should be some files in a folder. The files are 3 txt files and. The user account should be able to delete the files as it has full control on the folder that contains the files. Is there anything else I can investigate? – analyzethat Aug 05 '15 at 14:36
  • @Paolo the files are located on the same server as SQL Server runs on. I tried to avoid the hassle that comes with using UNC paths in the Execute Process Task. – analyzethat Aug 05 '15 at 14:37
  • 1
    @analyzethat Are the log files being created? Maybe it's the creation of the log file under the `Program Files (x86)` folder that it's having trouble with. I *believe* that you may need admin rights to create files under the `Program Files` and `Program Files (x86)` folders. – Ann L. Aug 05 '15 at 17:00
  • 1
    @analyzethat Thinking about it a bit more, those log files will be created in whatever the current directory is when the `cmd` session starts. If the `cmd` is run as `administrator`, that will be `C:\Windows\System32`! I would flesh out those log file names with specific paths, to non-system folders. (`Program Files` and `Program Files (x86)` are system folders.) – Ann L. Aug 05 '15 at 17:08

0 Answers0