Home » SQL ServerRSS

Restoring Database from .bak error: object cannot be cast from dbnull

I am attempting to restore a database on a Windows SQL 2008 Server from a .bak file. The .bak file was created on another machine running Windows SQL 2005 Server. It was copied between the two machines using an external HDD.

The error message is "Object cannot be cast from DbNull to other types". It appears when I click the 'contents' button in the Specify Backup dialog box after pressing 'add' [media] to specify the name and location of the .bak file. The .bak was copied from the external HDD onto an internal HDD (d:\backups\testme.bak)

I presume that the error message means that the contents of the file cannot be recognised. Does this mean that the .bak file is corrupt. What else might cause this problem?

I can restore the database from a .DMP (dump) file, but would prefer to use .BAK so in future I can just restore the changed records.

Steps

1. Log-in as the System Administrator (sa).

2. Select Databases and right click | Restore from Backup

3. Restore dialog set To = Image (name of new database) and From = Device, then click '...' button

4.  Specify Backup dialog box - click 'Add'

5. Add Media dialog - Browse and select Image.bak (not in the default SQL directory for backups). Press OK to return to the Specify Backup dialog box.

6. Specify Backup dialog box - click 'Contents' button and get error message "Object cannot be cast from DbNull to other types"

 

5 Answers Found

 

Answer 1

You will probably need to go all scripty to fix this.

The first command is:

RESTORE HEADERONLY from disk = '<full path and filename of backup file>'

Post back any errors or results.

 

Answer 2

Hi,

I suspect that your backup file has been corrupted. Please also run RESTORE VERIFYONLY (http://msdn.microsoft.com/en-us/library/ms188902.aspx) statement to check this backup set. If it actually corrupted, please try to use another copy backup file of the source database.

Thanks,
Chunsong

 

Answer 3

Looks like corruption.Another reason using WITH CHECKSUM, CONTINUE_AFTER_ERROR; within BACKUP DATABASE command

 

 

Answer 4

executing a RESTORE VERIFYONLY query yielded the error message "not a valid Microsoft Tape Format backup". Therefore, it seems that my backup file is indeed corrupt.

Makes the point that there is no point in doing backups without also doing an occasional restore!

 

Answer 5

Yep, only the actual restore database command will 'say' whether the .BAK is corrupted or not..

 

 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter