Attach DBs from a restored file on a disk

  • I had SQL Server on a Server and the OS went bad and I had to reinstall the OS. In doing so, the wrong disk was used to install the OS and Formated the disk with the SQL Data. I did not install anything on there, so I was able to restore the SQL db's to another disk with recover software. Now I am trying to reattach the db's but I get an error msg "Attach databases failed for...." "Database ... cannot be upgraded because it is read-only or has read-only files. make the database or files writeable, and rerun recovery. ... Error: 3415"

    How can I reattach these files?

  • Remove the Read-Only flag on the NTFS permissions for the MDF file (& LDF).

  • That's the first thing I tried, no cigar.

  • Make sure the files aren't read-only, make sure the folder isn't read-only (check parent folder too). Make sure that the SQL Server service account has full permissions on the files and folder.

    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
  • what is the sql server service acct (default)?

  • GrassHopper (7/30/2014)


    what is the sql server service acct (default)?

    Whatever you set it to!!

    Open sql server configuration manager on the server and check the acct in use for the sql and its agent service

    -----------------------------------------------------------------------------------------------------------

    "Ya can't make an omelette without breaking just a few eggs" 😉

  • that did not work. Running a recovery application on the file and it is recovering the db. It must be corrupt.

  • GrassHopper (7/30/2014)


    that did not work. Running a recovery application on the file and it is recovering the db. It must be corrupt.

    No. Corrupt databases do not give that error.

    Did you ensure that the folder isn't read only anywhere? That the file isn't? That the permissions are correct?

    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
  • Yes, checked rights and read only checkbox on folder and on file. I even moved the sql files to the default location for sql data files.

  • 2 db's were able to attach, the others did not and they are all in the same folder.

  • Try this, open powershell,

    cd databasefilelocation

    $Acl = Get-Acl "workingdatafile.mdf"

    Set-Acl "nonworkingdatafile.mdf" $Acl

  • I have windows 2008 R2 and I don't see powershell anywhere and can't find it to install it on my OS. It is 32 bit. Is it already installed?

  • Found it and installed it. I have to reboot the server, so I will have to wait till end of the day to reboot. I'll try it later. thanks.

  • Before I do this, what exactly does this do?

  • It will copy the NTFS permissions (known as an Access Control List or ACL) from a working MDF file (where the permissions are correct and work with SQL) to the non-working MDF (the one reporting read only errors). It's the same as manually copying the permissions from Security tab of the file. It's just a way to rule out permissions as an issue.

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

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