GibboK GibboK - 3 months ago 20x
SQL Question

sp_attach_single_file_db Error: failed with the operating system error 5(Access is denied.)

I'm trying to use this DataBase that come with this sample project with from MS:

So after I downloaded the files: I need to attach the .mdf DataBase to my Instance of MS SQL 2008.

From Management Studio Attaching DataBase does not work and event using this command i receive the same error:

sp_attach_single_file_db 'School.mdf', 'C:\School.mdf'


Msg 5133, Level 16, State 1, Line 1
Directory lookup for the file "C:\School.mdf" failed with the operating system error 5(Access is denied.).

Any idea what is wrong? Thanks for your help!


What operating system are you running on? Did you get an elevation prompt when you saved the file to the root of the C drive? What user account is SQL Server running under, and does it have permissions to read any files in the root of the C drive?

You might do better placing the file into %ProgramFiles%\Microsoft SQL Server\MSSQL10.<instance name>\MSSQL\DATA, alongside the other .mdf files that you know it can already read (adjust path above as necessary, but you hopefully get the idea).