SQL Server administration and T-SQL development, Web Programming with ASP.NET and Javascript, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software Kodyaz SQL Server and T-SQL Development Resources
Development resources, articles, tutorials, samples, codes and tools for .Net, SQL Server, Vista, etc.






Specified cast is not valid. (SqlManagerUI)

Specified cast is not valid. (SqlManagerUI) sql error message is a frequently asked error message.
This is thrown by SQL engine while database restore operations when source and target databases belong to different versions of Microsoft SQL Server.

If you try to restore a database backup file which belongs to a more recent SQL Server version on a database which is running relatively previous versions of SQL Server, you will probably get the error message .




Free SQL Comparison tools
Trusted by thousands of users
Download your copy now



Let's take backup of SQL Server 2011 database.
And try to restore SQL Server 2011 backup file on a SQL Server 2008 R2 database.
When you point the SQL Server 2011, Denali backup file and click OK buton to restore sql backup file, the following error message will be thrown.

SQL Server database restore error

Specified cast is not valid. (SqlManagerUI)

------------------------------
Program Location:

at Microsoft.SqlServer.Management.SqlManagerUI.SqlRestoreDatabaseGeneral. PopulateGridWithBackupSetsFromDevices()
at Microsoft.SqlServer.Management.SqlManagerUI.SqlRestoreDatabaseGeneral. GetBackupSetsFromDevices()
at Microsoft.SqlServer.Management.SqlManagerUI.SqlRestoreDatabaseGeneral. textDeviceSelected_TextChanged(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnTextChanged(EventArgs e)
at System.Windows.Forms.TextBoxBase.OnTextChanged(EventArgs e)
at System.Windows.Forms.Control.set_Text(String value)
at System.Windows.Forms.TextBoxBase.set_Text(String value)
at System.Windows.Forms.TextBox.set_Text(String value)
at Microsoft.SqlServer.Management.SqlManagerUI.SqlRestoreDatabaseGeneral. buttonSelectDevice_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

If you go further with the error and try to see the contents of the SQL Server 2011 database backup file, this time you will get probably the "Object cannot be cast from DBNull to other types. (mscorlib)" error.

SQL Server database backup file contents

Object cannot be cast from DBNull to other types. (mscorlib)

------------------------------
Program Location:

at System.DBNull.System.IConvertible.ToBoolean(IFormatProvider provider)
at System.Convert.ToBoolean(Object value, IFormatProvider provider)
at Microsoft.SqlServer.Management.SqlManagerUI.BakDevMediaContents.InitBackupSets(Restore sqlRestore)
at Microsoft.SqlServer.Management.SqlManagerUI.BakDevMediaContents.InitProp()
at Microsoft.SqlServer.Management.SqlManagerUI.BakDevMediaContents.InitializeOffline(CDataContainer dataContainer)
at Microsoft.SqlServer.Management.SqlManagerUI.BackupDeviceContents..ctor(CDataContainer dataContainer, IServiceProvider sp)
at Microsoft.SqlServer.Management.SqlManagerUI.SqlRestoreSelectBackupSource.buttonContents_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

An other method of sql restore database file can be directly using t-sql Restore command as follows:

RESTORE DATABASE SQLDenali FROM DISK = N'C:\sql2011.bak'

But this time since version conflict the following error message is thrown.

Msg 3241, Level 16, State 13, Line 1
The media family on device 'C:\sql2011.bak' is incorrectly formed. SQL Server cannot process this media family.
Msg 3013, Level 16, State 1, Line 1
RESTORE FILELIST is terminating abnormally.






Follow Kodyaz on Twitter

Related SQL Resources

SQL Server Articles

SQL Server 2012

SQL Server Tools

SQL Blog

SQL Server 2008 Blog

Certification Exams Blog

Reporting Services Blog

Analysis Services Blog

MS SQL Server Forums



Free Exam Vouchers









Copyright © 2004 - 2012 Eralper Yilmaz. All rights reserved.
Community Server, by Telligent Systems