Click here to Skip to main content
12,068,967 members (65,721 online)
Rate this:
 
Please Sign up or sign in to vote.
While attaching the mdf & ldf file in sql it is showing error

Unable to open the physical file "D:\Database1.mdf". Operating system error 5: "5(Access is denied.)". (Microsoft SQL Server, Error: 5120)
Posted 6-Mar-13 5:33am
Edited 1-Apr-14 21:54pm
v2
Comments
ThePhantomUpvoter 6-Mar-13 10:38am
   
ASP.NET? Or what? Details....
abhinavvijay 6-Mar-13 10:43am
   
SQL server
ThePhantomUpvoter 6-Mar-13 10:49am
   
You have "D:\Database1.mdf" in SQL Server and get access denied? Is that really your question? Do you really have a D: drive somewhere inside your SQL Server?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Open Computer Management Console.
Expand "Services and Applications" in treeview
Select "Services"
Tab "Standard" view
Scroll down to "SQL Server ("VA" ... (in caps ... sp?)" in list, right
(See Log On As) ... could be "Local System" OR "Network Service" OR "Local Service" OR ".\(username)"
Right click "SQL Server ("VA" etc) select "Properties"
Tab to "LogOn"
Change (I mean, "experiment") either "Local System Account" OR "This Account" until error goes away
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

try this...
GO to the folder r where you have stored mdf file. select file-> Right click ->click on . give full permissions to file for logged in user Security.
  Permalink  
Comments
Sharath.Mitte 23-May-14 15:52pm
   
thanks amol_B, it works for me:)
satish kankerwal 19-Aug-15 8:59am
   
its work
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 6

1- Run SQL Server Management as Administrator
2- Login SQL Server with Windows Authenticate
3- Attach you DB Files
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Root directories are often forbidden territory for write access - and SQL server needs that in order to attach the files.
Move them to a sub folder and give full access permissions to all users for all files in the folder.
  Permalink  
Comments
phil.o 7-Mar-13 5:00am
   
My 5, but I would rather give full access permission only to the account running the SQL Server service.
OriginalGriff 7-Mar-13 5:08am
   
Under normal circumstances, so would I - but that's a lot harder to explain how to do, particularly to what sounds like a beginner. Off the top of my head, I can't remember which user SQL server generally uses! :laugh:
phil.o 7-Mar-13 5:16am
   
I think (although I'm not absolutely sure about that) that, by default, SQL Server service runs under NTAUTHORITY\Local Service account.
I agree with you it's a bit tedious to describe the stages to find which account and verify it has the correct user permissions on the server/file system.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

In windows 8 the SQL Server role to add is "NT Service\MSSQLSERVER"
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 7

Change the permission levels to FullControl for that *.mdf file, which ever you trying to attach the database for loggedIn user account.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 8

go to the file right click- property - security- full control -ok
same on log file
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 10

Error :Msg 5120, Level 16, State 101, Line 1
Unable to open the physical file "c:\sqlserver\data\msdbtest_data.mdf". 
Operating system error 5: "5(Access is denied.)".

Log off your Computer.
And Run your SQL Management studio with Administrator
and try to Attach or Restore it.

It should work!!
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

Step 1->Right click the SQL Server management Studio Icon
Step 2->Run as administrator
Step 3->Try attaching the database
Step-4 the database should be attached.

Thanks
Ashish
  Permalink  
Comments
kefsan 7-Apr-14 11:54am
   
Thanks a lot, I hope you get all your dreams.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 9

Super and Fantastic.

S.N.Ramkumar, Chennai.
  Permalink  
Comments
RedDk 17-Nov-15 20:00pm
   
I'll go out on a limb here and guess that the Solution you've provided was a mistake and that you only wanted to leave a comment ... somewhere above in the column of responses to the poster's question ... because you found one of them to be helpful.

Commenting is done by posting in the "Have a Question or COmment" popup box and if you want to reply to other's comments choose the "Reply" button to do that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160208.1 | Last Updated 29 Jan 2016
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100