mssql '5 (Access is denied.)' error during restoring database

前端 未结 15 2018
忘了有多久
忘了有多久 2021-01-30 04:08

I want to restore a database from a file (Tasks → Restore → Database; after I select from device and select file) via SQL Server Management Studio.

After that, I get th

相关标签:
15条回答
  • 2021-01-30 04:23

    A good solution that can work is go to files > and check the reallocate all files

    Files relocate

    0 讨论(0)
  • 2021-01-30 04:25

    this happened to me earlier today, i was a member of the local server's admin group and have unimpeded access, or i thought so. I also ticked the "replace" option, even though there is no such DB in the instance.

    Found out that there used to be DB of the same name there, and the MDF and LDF files are still physically located at the data and log folders of the server, but the actual metadata is missing in the sys.databases. the service account of SQL server also can't ovewrwrite the existing files. Found out also that the files' owner is "unknown", i had to change ownership, to the 2 files above so that it is now owned by the local server's admin group, then renamed it.

    Then finally, it worked.

    0 讨论(0)
  • 2021-01-30 04:27

    I was getting the same error while trying to restore SQL 2008 R2 backup db in SQL 2012 DB. I guess the error is due to insufficient permissions to place .mdf and .ldf files in C drive. I tried one simple thing then I succeeded in restoring it successfully.

    Try this:

    In the Restore DB wizard windows, go to Files tab, change the restore destination from C: to some other drive. Then proceed with the regular restore process. It will definitely get restores successfully!

    Hope this helps you too. Cheers :)

    0 讨论(0)
  • 2021-01-30 04:27

    If you're attaching a database, take a look at the "Databases to attach" grid, and specifically in the Owner column after you've specified your .mdf file. Note the account and give Full Permissions to it for both mdf and ldf files.

    0 讨论(0)
  • 2021-01-30 04:28

    I found this, and it worked for me:

    CREATE LOGIN BackupRestoreAdmin WITH PASSWORD='$tr0ngP@$$w0rd'
    GO
    CREATE USER BackupRestoreAdmin FOR LOGIN BackupRestoreAdmin
    GO
    EXEC sp_addsrvrolemember 'BackupRestoreAdmin', 'dbcreator'
    GO
    EXEC sp_addrolemember 'db_owner','BackupRestoreAdmin'
    GO
    
    0 讨论(0)
  • 2021-01-30 04:29

    I tried the above scenario and got the same error 5 (access denied). I did a deep dive and found that the file .bak should have access to the SQL service account. If you are not sure, type services.msc in Start -> Run then check for SQL Service logon account.

    Then go to the file, right-click and select Security tab in Properties, then edit to add the new user.

    Finally then give full permission to it in order to give full access.

    Then from SSMS try to restore the backup.

    0 讨论(0)
提交回复
热议问题