0

I'm being unable to perform a backup in SQL Server 2005 installed on Windows 7 local machine. I was initially able to do so but as of now, every time I try I get the following message:

Backup failed for Server 'EBENEZERAKAGLO\SQLEXPRESS'. (Microsoft.SqlServer.Smo)

System.Data.SqlClient.SqlError: Cannot open backup device 'C:\Program Files (x86)\Microsoft SQL Server\MSSQL.3\MSSQL\Backup\Naass.bak'. Operating system error 5(Access is denied.). (Microsoft.SqlServer.Smo)

migrated from stackoverflow.com Feb 28 '13 at 13:09

This question came from our site for professional and enthusiast programmers.

  • Does the account under which the backup is running have access to that folder? – stuartd Feb 28 '13 at 10:29
  • Usually Windows7 keeps the folder C:\program files (x86) write locked for everyone. Your process doesn't have the permissions to write there. – Steve Feb 28 '13 at 10:29
  • or do you connect to that server remotely using any SQL management tools? – Akam Feb 28 '13 at 10:29
  • I initially visited that link but I don't know the steps to follow to get to the SQL Server Properties window shown. Can you please show me the steps? – Akaglo Feb 28 '13 at 10:39
4

Well, suppose you have a command to execute your backup like this

BACKUP DATABASE [naass] 
TO  DISK = N'C:\program files (x86)\Microsoft SQL Server\MSSQL.3\MSSQL\Backup\Naass.bak'' 
WITH NOFORMAT, INIT,  
NAME = N'naas-Complete Database Backup', 
SKIP, NOREWIND, NOUNLOAD,  STATS = 10

this will fail if the process that executes this command doesn't have the permissions to write in the mentioned folder. And Windows 7 (for very good security reasons) keeps the C:\program files folders and its subfolders write locked also to an administrator account.

You could mess with the default permissions and give to your folder above write permissions for your account but of course this is not the recommended way.
Much better, simply change the script to work on a different directory on your disks.

BACKUP DATABASE [naass] 
TO  DISK = N'D:\BackupSQL\naass.bak' 
WITH NOFORMAT, INIT,  
NAME = N'naas-Complete Database Backup'
SKIP, NOREWIND, NOUNLOAD,  STATS = 10

Of course this new directory should have the correct permissions.

Your Answer

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