CoNetrix Blog

5(Access is denied.) Error Restoring SQL Server 2005 Database

Posted on January 24, 2009 1:05 PM

I recently ran into a problem trying to restore a SQL Server 2005 database to a Windows XP machine.  The database back up was created on a Windows Vista machine and I thought that the different OS versions was the culprit.  However, it turned out to be related to SQL server instances and folder paths.  Here is full error I received when I attempted to restore the database using SQL Server Management Studio:

Restore failed for Server 'localhost\sqlexpress'.  (Microsoft.SqlServer.Express.Smo)

Additional information:
System.Data.SqlClient.SqlError: The operating system returned the error '5(Access is denied.)' while attempting 'RestoreContainer::ValidateTargetForCreation' on 'c:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\[my database name].mdf'. (Microsoft.SqlServer.Express.Smo)

I searched the Internet using the error message and found several posts stating that it was a problem with the privileges of the user account that my SQL Server Express service was running as. I hadn't changed the account it was running as and I had restored other databases in the past, but I checked the SQL Server Configuration Manager anyway.  As I suspected the service was still running as the default account (Network Service), so that wasn't it.  

After I couldn't find a quick fix on the Internet I decided to look around the options in the Restore Database window.  It turns out the problem was with the paths under the restore options.  The backup was trying to restore the .mdf and .ldf files to the c:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\ directory.  The instance of SQL Server I was working with was storing all it's data files in C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\.  Once I changed the paths for the database file and log file to be the same as where my other database files were being stored the restore ran fine with no errors.  For additional reference, here is an article that explains the naming of folders for SQL Server 2005 instances: http://weblogs.sqlteam.com/tarad/archive/2006/06/07/10114.aspx

Related Posts

Comments

Comment by sandra

February 17, 2009 6:12 AM

I checked in technet.microsoft.com/en-us/library/ms143170(SQL.90).aspx and found that microsoft recommend to use Local user for SQL Server Service. After I changed to Local System, it works!!!!

Comment by Joshua Rager

March 12, 2009 4:26 PM

Hey thanks so much for this post. I had to switch from "Program Files" to "Program Files (86). I spent may 5 minutes on this problem, you saved me so much time!

Comment by John Lomnicki

April 1, 2009 11:41 AM

Thanks, I was beginnning to get a bit short with the computer when I found post.

Comment by Ben Engelsberg

May 20, 2009 11:27 PM

Another thanks for this post! Fixed me right up!

Comment by Phil

May 27, 2009 5:37 AM

Yep, sorted me out too. Use the local sys account for the SQL services - perfect if running SQL Server from just one server (i.e. in a dev/test environment).

Comment by Roger

August 8, 2009 4:33 PM

I read the original solution and gave me a different idea. I went to the MSSQL.1\MSSQL folder and gave certain permissions to certain users and worked. Not sure why if I was loggin in to the SQL Server Management Studio as "sa" it was still not working.
After I changed the permissions on the folder, it worked.
Thanks.

Comment by Andre

September 21, 2009 7:57 AM

Thank you!!!... this worked great.

Comment by Sarah

October 9, 2009 2:02 PM

Thanks! that was SO helpful . and I looked at that patch a bunch and didn't even notice Data was not there.

Comment by Mike Kleiman

January 21, 2010 3:34 PM

Thank you for your post. What should have been a 5 minute task..... Thanks,

Add Comment





[b][/b] - [i][/i] - [u][/u]- [quote][/quote]