Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.