C# – Backup SQL Server Database Error ‘Operating System Error 5 (Access is Denied)’

csql serversql-server-2005

I have been trying to backup an sql server database, and I understand that this error is in regards to drive write protection. I am at the end of my rope with this, as nothing that I have found online has helped with this at all.

I have set up permissions for what should be considered every imaginable user that the server may try to pose as, everyone, administrators, my user, mssqlserver, sqlservermsasuser$xxx$MSSQLSERVER, SQLServer2005SQLBrowserUser, all with permissions set to full control.

I've tried running visual studio as admin, i've tried running the built application as admin, I've changed the "log on as" for the mssqlserver service to "Local System Account", me, and admin.

Yet still am having the same error, Operating System error 5 "Access is denied".
The folder is not read only, and is not in the root of the drive.
Any ideas??

Thanks in advance

Best Answer

Troubleshooting idea: Change the folder permissions temporarily to allow "Everyone", make the backup, then look at the backup file: File -> Properties -> Details -> Owner. Hopefully it lists the exact user. However its possible you need more than just this (not sure).

Some typical's are:

  • NT Service\MSSQL$InstanceName (displays as MSSQL$InstanceName)
  • NT Service\SQLAgent$InstanceName (e.g. backup made from a job, disp as SQLAgent$InstanceName)
  • System,
  • Network Service,
  • machine_name$ (for remote backups)
  • and the user login doing the backup.