Attach database failed for Server […] Unable to open the physical file “[…]”. Operating system error 5: “5(failed to retrieve text for this error. Reason: 15105)”. (Microsoft SQL Server, Error: 5120)

Problem

2010_6_DB_attach_fail

– bummer. This is some permission issue. It seemed, 2 things can cause this error:

  1. trying to attach an mdf-file, that has not been detached (properly)
  2. some other stuff, which was my case. Never found out what (as I did, indeed, detach this database first)

What I tried first

  • Moving mdf- and log-files to somewhere else, retry -> fail
  • trying to give my SQLSERVER/SQLEXPRESS service(s) modify-permissions on my DB-folder. The use NETWORK_SERVICE as default. This caused, btw, an error, when applying the modify-rights to the individual (db-)files in the folder. Oh: -> fail
  • Cursing, random rebooting. Lots of that kind of stuff

Solution

1 hour of googling and uber-fail led me to somewhere (i closed the tab – sorry for the missing reference), suggesting running the Management Studio Instance as an administrator. Guess what: WIN!

Join the conversation

  • Valery - 8 years ago

    In order to successfully attach of a database with SQL (Express), the account configured to run the service (Check via the “SQL Server Configuration Manager”) must be granted “FULL CONTROL” access on the folder where the database files are located. “MODIFY” access right is not enough !

    V.

  • Tareq Mansour - 7 years ago

    thanks you, it was annoying me

  • Lhasson - 7 years ago

    Thanks so much.

  • dwe306 - 7 years ago

    Thank you for taking the time to post this solution. Much as trying to get my head around Visual Web Developer and SQL Server Express is – hitting brick walls every 5 seconds where what the help says to do doesn’t acutally work and there’s no clues as to why – you can have too much of a good thing and I’m on the verge of taking an axe to the PC at this point … so the solution to this was much appreciated, thank you.

  • dwe306 - 7 years ago

    Syntax error – that should’ve read:

    Thank you for taking the time to post this solution. Much as trying to get my head around Visual Web Developer and SQL Server Express is FUN – hitting brick walls every 5 seconds where what the help says to do doesn’t acutally work and there’s no clues as to why – you can have too much of a good thing and I’m on the verge of taking an axe to the PC at this point … so the solution to this was much appreciated, thank you.

  • Nemat - 6 years ago

    tanks so much
    iran-urmia

  • Seema C - 6 years ago

    thanks so much Valery … your said workaround worked for me.

  • sacheinbaala - 6 years ago

    Thanks a lot.. it worked 🙂

  • puneet - 6 years ago

    thanks giving full control.. worked

  • Ouss - 5 years ago

    Thank you so much !

  • raph - 5 years ago

    It has just worked. THANK YOU for sharing this trick !

  • Bysiol - 5 years ago

    Thank you so much! PL

  • Enrique Mallon - 4 years ago

    Error 5 usually means a security issue – ensure that the SQL
    Server service account has the permissions to work on that directory/file. Read
    more and resolve it from here: http://www.sqlrecoverysoftware.net/blog/sql-error-15105.html

  • Niall - 2 years ago

    Good one – two days of stuffing around before I found your post. Give yourself a beer or three on my tab. Thanks 🙂