Restoring DB in SQL Server executing a query command

I was having a problem trying to restore a DB from a backup with the error message “Error 3154: The backup set holds a backup of a database other than the existing database.“.

I finally found how to make it executing a manual query instead than trying to use SQL Server menu options. To execute the query you need to open a Query and execute it from Master, not from the db to restore.

ALTER DATABASE MyDatabaseName
SET SINGLE_USER WITH
ROLLBACK IMMEDIATE
RESTORE DATABASE MyDatabaseName
FROM DISK = 'MyDatabaseName.bak'
WITH REPLACE

The fix consists on using that “WITH REPLACE” sentence.

Note: The page where I got the query sets the backup file using “c:/Filename.bak” but my SQL Server was configured to look into C:/Program Files/SQL Server/…/backups/ and on setting c:/ it confused itself and tried to get it from “C:/Program Files/SQL Server/…/backups/C:/” not being able to find it. If you save the backup inside the SQL Server backups folder then you can just write the filename without having to set the path (if you don’t know the path just execute the query and the error message will tell you where it is).

Leave a Reply

Close Bitnami banner
Bitnami