Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-server-2005 SQL
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 at 6-Mar-13 10:38am
   
ASP.NET? Or what? Details....
abhinavvijay at 6-Mar-13 10:43am
   
SQL server
ThePhantomUpvoter at 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 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 at 23-May-14 15:52pm
   
thanks amol_B, it works for me:)
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 at 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 at 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 at 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 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 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 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 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 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 at 7-Apr-14 11:54am
   
Thanks a lot, I hope you get all your dreams.

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

  Print Answers RSS
0 OriginalGriff 515
1 Maciej Los 290
2 Richard MacCutchan 265
3 BillWoodruff 235
4 Suraj Sahoo | Coding Passion 175
0 OriginalGriff 8,804
1 Sergey Alexandrovich Kryukov 7,457
2 DamithSL 5,689
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411028.1 | Last Updated 12 Nov 2014
Copyright © CodeProject, 1999-2014
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