5

I am trying to add the AdventureWorks sample database to SQL Server 2012, but I get an error message:

Msg 5133, Level 16, State 1, Line 1 Directory lookup for the file "C:\Users\A\Documents\SQL Server Management Studio\Data\AdventureWorks2012_Data.mdf" failed with the operating system error 5(Access is denied.).

migrated from stackoverflow.com Jul 2 '12 at 9:45

This question came from our site for professional and enthusiast programmers.

3

The error message seems pretty straightforward: Access is denied. You need to make sure the SQL Server service account has adequate permissions on C:\Users\A\Documents\SQL Server Management Studio\Data\, or better yet, move the MDF (and LDF, if it exists) to the default data/log folders for the instance (where this shouldn't be a problem, and which is a better home for your database files anyway).

You can find the default data/log folders by inspecting:

SELECT physical_name FROM sys.master_files;

Any of the paths presented here should be a valid location to use...

1

I would put the .mdf file in the default DATA directory, it will probably be something like:

 C:\Program Files\Microsoft SQL Server\MSSQL11.INSTANCE_NAME\MSSQL\DATA 

or

C:\Program Files\Microsoft SQL Server\MSSQL11\MSSQL\DATA

The sever probably can't find the log file, this script rebuild the log (.ldf) file.

CREATE DATABASE AdventureWorks2012_Data
ON (FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.INSTANCE_NAME\MSSQL\DATA\AdventureWorks2012_Data.mdf')
FOR ATTACH_REBUILD_LOG 
Go
locked by Community Oct 9 '14 at 20:28
-1

While creating a new database provide database path outside users folder . So , lot of permissions related issue are solved

enter image description here

New contributor
Harsh is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy