Msg 3154, The backup set holds a backup of a database other than the existing database

This is a repost of a post from an old blog, made on March 15, 2012, that used to be on:

http://wp.me/p25nt4-4A

http://adminramble.com/msg-3154-backup-set-holds-backup-database-existing-database/

Original post:

I got asked for help today at work by a coworker who got the following error when trying to restore a database to a different already existing database:

System.Data.SqlClient.SqlError: The backup set holds a backup of a database other than the existing ‘database_name’ database. (Microsoft.SqlServer.Smo)

when trying to restore with script he would get something like this:

Msg 3154, Level 16, State 4, Line 1
The backup set holds a backup of a database other than the existing ‘database_name’ database.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.

The solution for this is simple: you need to add WITH REPLACE option when restoring.

If you’re using script it should look something like this:

RESTORE DATABASE [database_name] FROM  DISK = N'C:\some_directory\backup.bak' WITH  FILE = 1,  NOUNLOAD,  STATS = 10
GO

If you’re using GUI you need to mark the on the Options section.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.