I am unable to execute batch files to copy backups from SQL Server 2008 R2 hosted on Windows 2008 R2 to a file share.


Access denied

SQL Server Agent service has full control on the soure and destination folders.

This only happens in Windows Server 2008 R2 on my production environment, suspecting additional security controls on Windows Server 2008 causing this issue.

  • access denied means the account that is trying to access dont have access to the file share. Check security settings or with your windows Admin. – Kin Shah Jul 19 '13 at 12:58
  • 2
    What account is the SQL Server Agent service logging in as? Have you logged in as that user and verified that they do have rights to the file share? – Aaron Bertrand Jul 19 '13 at 14:25
  • Hi Aaron,Thanks for the reply, yes i did verify the permissions it can able to write it with the account. Will there be any security policy in windows2008 will prevent it to be writing? – Sun27 Jul 19 '13 at 14:41
  • 1
    If you log in as the SQL Server Agent service account (assuming you can) are you able to run the bat file? Are you using xp_cmdshell to execute the bat file or a command step in your job? Do you have a "Run As" set for the job step? – Kenneth Fisher Jul 19 '13 at 15:59
  • 1
    Kenneth's answer has some good advice. Keep in mind that you also need to look at the NTFS and share permissions. The more restrictive of the two permissions sets will apply. – James Lupolt Jul 20 '13 at 10:16

If you are running the batch file through xp_cmdshell you are using a different set of permissions. Here is the BOL entry for xp_cmdshell.

Basically though if you are running it as a sysadmin then xp_cmdshell uses the service account for SQL Server, not the service account for the Agent. If you are not running it as a sysadmin then it uses a proxy account. The proxy account is stored in credential called ##xp_cmdshell_proxy_account##.

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.