SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
Development resources, articles, tutorials, code samples, tools and downloads for ASP.Net, SQL Server, Reporting Services, T-SQL, Windows, AWS, SAP HANA and ABAP


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.

Let's take backup of SQL Server 2012 database.
And try to restore SQL Server 2012 backup file on a SQL Server 2008 R2 database.
When you point the SQL Server 2012, 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 2012 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:
/p>

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

Code

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:\sql2012.bak' is incorrectly formed. SQL Server cannot process this media family.
Msg 3013, Level 16, State 1, Line 1
RESTORE FILELIST is terminating abnormally.



SQL Server

SQL Server 2019 Installation
download SQL Server 2019
download SQL Server 2017
download SQL Server 2016
download SQL Server 2014
download SQL Server 2012
MacOS ve SQL Server 2019


Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.