SQL-Server: The backup set holds a backup of a database other than the existing

前端 未结 24 1774
天命终不由人
天命终不由人 2020-12-07 06:49

I am trying to restore a SQL Server backup file for my database, but it is throwing an error as follow:

The backup set holds a backup of a database ot

相关标签:
24条回答
  • 2020-12-07 07:08

    Its because the .mdf and .ldf Files from the original Db were locate at maybe c:\programFile\.... and this info is saved in the Backup!

    If you create the same DB on a different SQL Server where the installation is on c:\program Files (x86)\ .... you can not restore as usually. You need to relocate the path for .mdf and .ldf Files.

    Therefore:

    • Create a empty DB on the new Server

    • Right click on the empty Db > Tasks > Restore > Database > click Device select your .bak Files > Select Db to restore into

    • click on Files at left side > Select "Relocate all Files to Folder"
    • click Options on the left site > click on Overwrite

    Done!
    Hope it helps!

    0 讨论(0)
  • 2020-12-07 07:08

    If you are using the script approach and have an error concerning the LDF and MDF files, you can first query the the backup file for the logical names (and other details) of files in the backup set, using the following:

    -- Queries the backup file for the file list in backup set, where Type denotes 
    -- type of file. Can be L,D,F or S
    -- info: https://docs.microsoft.com/en-us/sql/t-sql/statements/restore-statements-filelistonly-transact-sql
    RESTORE FILELISTONLY FROM DISK = 'C:\Temp\DB_backup.bak'
    GO
    

    You will get results similar to the following:

    And then you can use those logical names in the queries:

        -- Script assumes you want MDF and LDF files restored on separate drives. Modify for your scenario
        RESTORE DATABASE DB 
        FROM DISK='C:\Temp\DB_backup.bak'
        WITH REPLACE,
          MOVE 'DB' TO 'E:\MSSQL\Data\DB.mdf', -- "DB" is the mdf logical name from query above
          MOVE 'DB_log' TO 'F:\MSSQL\Logs\DB.ldf'; -- "DB_log" is LDF logical name from query above
    

    More info on RESTORE FILELISTONLY can be found from the SQL Server docs.

    0 讨论(0)
  • 2020-12-07 07:08

    system.data.sqlclient.sqlerror:The backup set holds a backup of a database other than the existing 'Dbname' database

    I have came across to find soultion

    1. Don't Create a database with the same name or different database name !Important.

    2. right click the database | Tasks > Restore > Database

    3. Under "Source for restore" select "From Device"

    4. Select .bak file

    5. Select the check box for the database in the gridview below

    6. To DataBase: "Here You can type New Database Name" (Ex:DemoDB)

    7. Don't select the Existing Database From DropDownlist

    8. Now Click on Ok Button ,it will create a new Databse and restore all data from your .bak file .

    you can get help from this link even

    Hope it will help to sort out your issue...

    0 讨论(0)
  • 2020-12-07 07:10

    Simple 3 steps:

    1- Right click on database → Tasks → restore → Database

    2- Check Device as source and locate .bak (or zipped .bak) file

    3- In the left pane click on options and:

    • check Overwrite the existing database.
    • uncheck Take tail-log backup before restore
    • check Close existing connection to destination database.

    Other options are really optional (and important of course)!

    0 讨论(0)
  • 2020-12-07 07:12
    USE [master];
    GO
    
    CREATE DATABASE db;
    GO
    
    CREATE DATABASE db2;
    GO
    
    BACKUP DATABASE db TO DISK = 'c:\temp\db.bak' WITH INIT, COMPRESSION;
    GO
    
    RESTORE DATABASE db2
      FROM DISK = 'c:\temp\db.bak'
      WITH REPLACE,
      MOVE 'db' TO 'c:\temp\db2.mdf',
      MOVE 'db_log' TO 'c:\temp\db2.ldf';
    
    0 讨论(0)
  • 2020-12-07 07:13

    I had ran into similar problem today. Tried all the above solutions but didn't worked. So posting my solution here.

    Don't forget to uncheck Tail-long Backup before restore

    Don't forget to uncheck Tail-long Backup before restore

    Hope it help others too!

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