-2

I am trying to attach a .mdf file. I used the following code:

CREATE DATABASE Antonio
ON (FILENAME = 'c:\Users\asaponar\Desktop\antonio lon\ION_Data_Archivemarch.mdf')
FOR ATTACH

but I get the following message :

Msg 5133, Level 16, State 1, Line 1 Directory lookup for the file "c:\Users\asaponar\Desktop\antonio lon\ION_Data_Archivemarch.mdf" failed with the operating system error 5(Access is denied.).

For sure the file permissions are right.

Anything else to check please?

KrazzyNefarious
  • 3,202
  • 3
  • 20
  • 32
antonio
  • 77
  • 10
  • rights over the mdf file is missing ! – Up_One Mar 21 '14 at 16:22
  • You asked the same question [before](http://stackoverflow.com/questions/22558988/problems-with-attaching-a-database-in-sql-server-error-5133) and it was closed as a duplicate. So this is a duplicate of a duplicate!!! – huMpty duMpty Mar 21 '14 at 17:04
  • @huMptyduMpty i have checked but the problem still exists – antonio Mar 21 '14 at 17:13
  • @antonio: But you can't ask the same question twice!!! [How should duplicate questions be handled?](http://meta.stackexchange.com/questions/10841/how-should-duplicate-questions-be-handled) – huMpty duMpty Mar 21 '14 at 17:14

3 Answers3

1

Make sure that the account running the SQL SERVER service has complete rights over the *.MDF file you are about to attach!

Up_One
  • 5,213
  • 3
  • 33
  • 65
1

Might be folder or file permission issue, try to move your .mdf files to Folder where your SQL server is located i.e.

%ProgramFiles%\Microsoft SQL Server\MSSQL11.<instance name>\MSSQL\DATA

Than login to Management studio as administrator or windows account, and try to attach.

Hope this will help! Thanks Suresh

Suresh
  • 1,131
  • 1
  • 15
  • 28
  • Thank you very much it worked in that way...I still don't understand the reason but it worked :) . Also it created automatically an ldf file. Now i have other basic questions? How could i see the content of this mdf file? If I try simply to open it, in visual studio the database appears all messed up. What should i do next? – antonio Mar 24 '14 at 10:35
  • Location from where you was trying to restore Database was not accessible to SQL service, and by moving DB to service folder it resolve permission issue. For view Data you can't you able to see your tables? and does it not allowing you to view data there? – Suresh Mar 24 '14 at 12:21
  • Maybe it does...and as well i don't know how to see them..If i click on tables in antonio database folder...a lot of files appears...but none of them look as simple table...but for sure i am wrong.. – antonio Mar 24 '14 at 12:37
  • Hope this would help to understand how to use Management Studio http://tinyurl.com/oqosxly – Suresh Mar 24 '14 at 13:12
0

A litmus test is to copy and paste the file in file explorer. If you can do that, use the Windows authentication in SQL Server Management Studio to attach the file

Milena Petrovic
  • 2,651
  • 21
  • 18