Sql-server – I can backup the SQL Server 2008 R2 but can’t restore from the very same folder

backupcrestoresql-server-2008-r2

I ran a backup into a folder. The Network Service has full control access to this folder. The backup process didn't work until I granted that account full control.

I try to restore that same file but I get an error

Operating system error 5 (failed to retrieve text for this error. Reason: 15105).

If I move the file to the instance's actual folder it restores fine, so the file itself is not bad.

Is there something slightly different in the folder rights needed to run a backup versus a restore? What is that difference? FYI, I am doing all this programmatically using a C# application. To test the above backup/restore, I've used the server management tool.

The user access was done via the C# code, though. Here is the main line:

myDirectorySecurity.AddAccessRule(new FileSystemAccessRule(sqlserviceuser,FileSystemRights.FullControl,AccessControlType.Allow));

I connect to the database using a SQL Server authenticated user, not a Windows user, so I can't add the 'logged in' user as full control to the folder.

Best Answer

found it. turns out the permissions command I was using isn't enough for a restore (it's enough for the backup). Granting the full access rule on the folder isn't enough - it has to be on "the folder, subfolders and files".

basically two more lines of code:

myDirectorySecurity.AddAccessRule(new FileSystemAccessRule(sqlserviceuser, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow));

myDirectorySecurity.AddAccessRule(new FileSystemAccessRule(sqlserviceuser, FileSystemRights.FullControl, InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));