3

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.

  • can you tell me, how you restore the 'backup' file. – Md Haidar Ali Khan Mar 16 '15 at 5:22
  • You have to grant permissions to the user SQL Server runs as. You can check that using SQL Server Configuration Manager or services.msc (not recommended) – BuahahaXD Mar 16 '15 at 5:40
  • 1
    Is it possible that the restore is failing due to lack of permissions on the destination folder(s) for the data/log files? Can you show the actual restore command you're using? – Aaron Bertrand Mar 16 '15 at 14:13
  • other then the granting of access to the folder (to the Network Service user, who is the login user for the SQL Server services), i am doing everything via the Management console. I can backup the database to the folder.. then immediately try and restore and it fails. I copy the file to the instance's folder, and the restore will work fine. the 'command' in the management studio is right clicking on the database -> Tasks -> Restore -> database... – daBich Mar 16 '15 at 22:25
  • I'll stress that the restore works fine from the instance's folder if i take the very same file i tried in the other folder... but the backup works fine in either folder. is there anything Restore requires more as far as folder access rights, compared to backups? – daBich Mar 16 '15 at 22:31
0

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));

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.