[sql-server] SQL Server database restore error: specified cast is not valid. (SqlManagerUI)

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 localhost as a database.

Few days back my SQL Server crashed and I had to install a new 2008 R2 Express version on my localhost. It worked fine when I restored some older versions taken from Express edition but when I try to restore database from .bak file which is taken from production server it is causing the following error:

Error: Specified cast is not valid. (SqlManagerUI)

and when I try to restore the database using command

Use Master
Go
RESTORE DATABASE Publications
FROM DISK = 'C:\Publications.bak'
WITH MOVE 'Publications' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS2008R2\MSSQL\DATA\Publications.mdf',--adjust path
MOVE 'AlPublications_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS2008R2\MSSQL\DATA\Publications.ldf'

It generates a different error

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

I have cross checked the versions. They all seem matching to me as shown in the image below

Previously I was able to restore a database from standard version to express edition but now it fails. I deleted the database and tried to recreate it. That fails, too.

I am not sure what I am doing wrong. I would appreciate help in this regarding

Issue was resolved as it seems .bak file was corrupt. When I tried it with a different file it worked.

This question is related to sql-server sql-server-2008 database-restore

The answer is


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


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


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!


Examples related to sql-server

Passing multiple values for same variable in stored procedure SQL permissions for roles Count the Number of Tables in a SQL Server Database Visual Studio 2017 does not have Business Intelligence Integration Services/Projects ALTER TABLE DROP COLUMN failed because one or more objects access this column Create Local SQL Server database How to create temp table using Create statement in SQL Server? SQL Query Where Date = Today Minus 7 Days How do I pass a list as a parameter in a stored procedure? SQL Server date format yyyymmdd

Examples related to sql-server-2008

Violation of PRIMARY KEY constraint. Cannot insert duplicate key in object How to Use Multiple Columns in Partition By And Ensure No Duplicate Row is Returned SQL Server : How to test if a string has only digit characters Conversion of a varchar data type to a datetime data type resulted in an out-of-range value in SQL query Get last 30 day records from today date in SQL Server How to subtract 30 days from the current date using SQL Server Calculate time difference in minutes in SQL Server SQL Connection Error: System.Data.SqlClient.SqlException (0x80131904) SQL Server Service not available in service list after installation of SQL Server Management Studio How to delete large data of table in SQL without log?

Examples related to database-restore

How to import a bak file into SQL Server Express Restoring database from .mdf and .ldf files of SQL Server 2008 Enable binary mode while restoring a Database from an SQL dump SQL Server database restore error: specified cast is not valid. (SqlManagerUI) How to restore PostgreSQL dump file into Postgres databases? Error: Specified cast is not valid. (SqlManagerUI) Import .bak file to a database in SQL server