3

I am trying to attach the AdventureWorks database with the following query:

CREATE DATABASE AdventureWorks2012
ON (FILENAME = 'C:\AdventureWorks2012_Data.mdf')
FOR ATTACH_REBUILD_LOG ;

But I get the following error:

Create file encountered operating system error 5 (access is denied.) while attempting to open the physical file blah

Note: I am using Windows auth mode.

Any pointers as to what to do?

1
  • Please also note that Attaching database MDF file without LDF file would only work if database was shutdown cleanly. If not you might not be able to attach even if you solve access denied message – Shanky Oct 3 '14 at 16:52
10

SQL Server service account don't have permission in the drive you are using to create database.Don't put you database in the root of drive. It would be problematic if you have UAC enabled, Create a folder in drive. Like D:\Data

Check this http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx

ERROR_ACCESS_DENIED
5 (0x5)
Access is denied.

Make sure that the SQL Server Service Account has read/Write permission to the folder where database file is kept or use the instance default folder of Data/Log where it will already have such permissions.

2
0

if you have installed your SQL server in your local machine, your name should be having the permission to the folder from which you are trying to retrieve the data file.

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.