"Sql server error 5120" while attaching database

  • lays.babyblush


    Points: 401


    I am trying to attach few databases to sql server 2005.I have my .mdf files in "D:\MSSQL\Data" and my .ldf files in "E:\SQLLogs".

    when i try to attach it gives me below mentioned error


    Unable to open the physical file "D:\MSSQL\Data\dbAcquisitionStaging_Data1.mdf". Operating system error 5: "5(Access is denied.)". (Microsoft SQL Server, Error: 5120)

    For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=09.00.3042&EvtSrc=MSSQLServer&EvtID=5120&LinkId=20476


    I am added as administrator to this server. I checked for permissions on the .mdf and .ldf files It says full control.

    Could anybody please advise on how to fix this issue.This is hindering my progress. Any kind of help will be greatly appreciated.

    Thanks in advance


  • RRIOS42

    SSChasing Mays

    Points: 604

    need to check permissions to the actual file directories if all good then have your admin reset them, this has more to do with permissions with the directory you are trying to read and write.

  • David Webb-CDS


    Points: 17338

    Check the account under which SQL Server is running. That's the account that needs to have permissions to the files.

    And then again, I might be wrong ...
    David Webb

  • lays.babyblush


    Points: 401

    Thanks for the response.

    The problem is fixed. as the .mdf and .ldf files where on different drives

    it was giving some wierd error so i attached only mdf files and the server created .ldf files on the same drive as mdf. this way i could attach it but then i took the db offline copied the log from D:\ to E:\ and then brought the db online. it worked.

    thanks a ton for the responses.

  • dotnet-786228

    SSC Journeyman

    Points: 81

    Hello !!!

    try login with Windows Authentication.


  • anjan.ashok


    Points: 2783

    Hi Lays,

    How did u copy the log from D:\ to E:\ as mentioned.

    this way i could attach it but then i took the db offline copied the log from D:\ to E:\ and then brought the db online. it worked.

    Pls tell me how did u do this.

    Thanks in advance.

  • bijvoets

    SSC Enthusiast

    Points: 142

    Although it's an old post, this problem is still actual. As this post wasn't closed with a working solution, I write it here:

    Start SQL Server manager as Administrator (right-click on the program, choose "Start as administrator"): problem solved!

    I wrote this solution on Developer's Challenges, SQL Server Error 5120 .

  • kyongaya

    SSC Enthusiast

    Points: 113

    You are some amazing!

    Yes, it works perfectly.

    Thanks a lot ๐Ÿ˜€

  • rasool7

    SSC Journeyman

    Points: 91

    If you are using windows 7. Open the studio management by Right click and

    Run as Administrator. then log on in windows mode and try to attach the database . It will work for sure :w00t:

  • viet.anh

    SSC Enthusiast

    Points: 113

    dotnet-786228 (6/18/2008)

    Hello !!!

    try login with Windows Authentication.


    Yaaaaaaaaaaa, this solution work fine ๐Ÿ˜€

    Viet Anh,


  • bkong

    SSC Journeyman

    Points: 89

    Thank You Very Much:-)

  • bigeorge179

    SSC Journeyman

    Points: 91

    THANK YOU!!!!!!!!!!!!! You saved me from more hours of frustration ๐Ÿ™‚

  • WellingtonSQL

    SSC Veteran

    Points: 210

    Hello Mr.

    รจ an old post, but decided that situation as follows:

    When you attach the base within the D: \ <folder> \ MSSQL \ Data presented this error so I created another folder inside the Data folder put the base you want to attach inside the folder I created and it worked then the path was D: \ <folder > \ MSSQL \ Data \ <new <folder

    Note: We attach multiple database within the directory D: \ <folder> \ MSSQL \ Data, and have never been read-only just this last.

  • RuedeMalte

    SSC Enthusiast

    Points: 166

    Hello, I'm receiving this error also. I'm trying to attach some databases that came with the MCTS 70-433 Exam Training Kit. After copying the databases from the CD to my hard drive, two of the databases attached fine. But a third, which required I copy an .ldf file, an .mdf file, and a documents folder, will not attach. The error message says that it cannot find the Documents file specified. Which is weird, because it's in the same place as the data files. It's looking for '\MSSQL10.MSSQLSERVER\MSSQL\DATA\DOCUMENTS' but the default name of the program file given (which I can't/don't know how to change) is '\MSSQL10_50MSSQLSERVER\MSSQL\DATA....'

    Just trying to learn SQL Server after learning Oracle.

    Any help on this? I'm running Windows 7, SQL Server 2008 R2. And I've logged in Windows Authentication mode. Thanks in advance.

  • Gail Shaw

    SSC Guru

    Points: 1004474

    Please post new questions in a new thread. Thanks

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 15 posts - 1 through 15 (of 27 total)

You must be logged in to reply to this topic. Login to reply