Sunday, December 29, 2013

Error Attach Database failed for server ‘xxxxx’ Unable to open physical file Error 5120

9 comments
An Exception occurred while executing a Transact-SQL statement  or batch .Unable to open the physical file ‘XXXXX’ Operating System error  5: “5(Access is Denied)” (Microsoft SQL Server Error :5120)

Error Snapshot :

Cause of Error 5120 in SQL SERVER:
This error is caused while trying to attach .mdf file moved from its default storage location to any other hard drive of the computer. To solve this error the hard disk drive from which you are trying to attach database file(.mdf) should have read/ write permission.
Steps to solve error Attach Database failed for server: ‘XXXX’:
Step 1: Right click on the hard disk drive from which you are attaching the database file(.mdf) and select properties as shown in the diagram below:
An Exception occurred while executing a Transact-SQL statement


Step 2: Now in properties window select Security tab and in security tab select Group or User Names and click on Edit Button as shown in the diagram below:

An Exception occurred while executing a Transact-SQL statement


Step 3: Select User name of PC and give all the permission for user by selecting all check boxes and then click on Apply button and finally click on ok button as shown in the diagram below:
An Exception occurred while executing a Transact-SQL statement


Now try to attach the database file again from sql server management studio.

9 comments:

  1. I tried and my problem is solved. Thanks you for a good job done and may God richly Bless you

    ReplyDelete
    Replies
    1. If you try to attach a database in Standby then you may get “Is not a primary database file, Microsoft SQL Server, Error: 5171”. This is the reason that leads to corruption of SQL files and database which can be more destructive enough to shutdown of the whole system. SQL MDF Repair Tool is the only solution to get rid of this problem and helps you to retain the MDF file quickly and efficiently. This powerful recovery tool will help to fix all the possible errors of SQL database and enable accessibility to even crucial data.

      http://sqlmdf.filerepairtool.net/blog/unable-restoreattach-mdf-file

      Delete
  2. @Simon: Thanks for you comment. Keep reading the blog for other asp.net solutions as well.

    ReplyDelete
  3. Thanks, this solved my problem

    ReplyDelete
  4. For a perfect solution for this kind of attachment error then you must read this article :- http://www.sqlrecoverysoftware.net/blog/microsoft-sql-error-5220.html

    ReplyDelete
  5. it may be very useful.....
    keep updates in the same manner...which will be useful to everydody in a diagramatic manner

    ReplyDelete
  6. Thank you for clear, concise instruction - it works!

    ReplyDelete
  7. Thank you - it worked. I have another question though: Should the permissions be reset on those .mdf and .ldf files after attaching them? Does it introduce a potential security risk leaving them like that?

    ReplyDelete