SQL Server database restore error: specified cast is not valid. (SqlManagerUI)

前端 未结 4 790
情书的邮戳
情书的邮戳 2020-12-13 23:07

I am using SQL Server 2008 R2 Standard (version 10.50.1600.1) for my production website and SQL Server Express edition with Advanced Services (v10.50.1600.1) for my localho

相关标签:
4条回答
  • 2020-12-13 23:21

    Below can be 2 reasons for this issue:

    1. Backup taken on SQL 2012 and Restore Headeronly was done in SQL 2008 R2

    2. Backup media is corrupted.

    If we run below command, we can find actual error always:

    restore headeronly
    from disk = 'C:\Users\Public\Database.bak'
    

    Give complete location of your database file in the quot

    Hope it helps

    0 讨论(0)
  • 2020-12-13 23:26

    The GUI can be fickle at times. The error you got when using T-SQL is because you're trying to overwrite an existing database, but did not specify to overwrite/replace the existing database. The following might work:

    Use Master
    Go
    RESTORE DATABASE Publications
      FROM DISK = 'C:\Publications_backup_2012_10_15_010004_5648316.bak'
      WITH 
        MOVE 'Publications' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS2008R2\MSSQL\DATA\Publications.mdf',--adjust path
        MOVE 'Publications_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS2008R2\MSSQL\DATA\Publications.ldf'
    , REPLACE -- Add REPLACE to specify the existing database which should be overwritten.
    
    0 讨论(0)
  • 2020-12-13 23:34

    Could be because of restoring SQL Server 2012 version backup file into SQL Server 2008 R2 or even less.

    0 讨论(0)
  • 2020-12-13 23:39

    Finally got this error to go away on a restore. I moved to SQL2012 out of frustration, but I guess this would probably still work on 2008R2. I had to use the logical names:

    RESTORE FILELISTONLY
    FROM DISK = ‘location of your.bak file’
    

    And from there I ran a restore statement with MOVE using logical names.

    RESTORE DATABASE database1
    FROM DISK = '\\database path\database.bak'
    WITH
    MOVE 'File_Data' TO 'E:\location\database.mdf',
    MOVE 'File_DOCS' TO 'E:\location\database_1.ndf',
    MOVE 'file' TO 'E:\location\database_2.ndf',
    MOVE 'file' TO 'E:\location\database_3.ndf',
    MOVE 'file_Log' TO 'E:\location\database.ldf'
    

    When it was done restoring, I almost wept with joy.

    Good luck!

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