Ошибка specified cast is not valid sql

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 FilesMicrosoft SQL ServerMSSQL10_50.SQLEXPRESS2008R2MSSQLDATAPublications.mdf',--adjust path
MOVE 'AlPublications_log' TO 'C:Program FilesMicrosoft SQL ServerMSSQL10_50.SQLEXPRESS2008R2MSSQLDATAPublications.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.

  • Remove From My Forums
  • Question

  • My environment is:

    Operating System: Windows 7 Pro (32bit), Finnish

    I use Virtual PC including in Windows 7

    Operating system in Virtual PC: Windows Server 2008 Standard.

    SQL Sever 2008 R2

    Under SQL Server Management Studio,

    I have a database backup file created by different user in same environment (Virtual PC + Windows Server2008 + SQL Server 2008 R2)

    When I try to restore a Database from backup file I get following message:

    TITLE: Microsoft SQL Server Management Studio
    ——————————

    Specified cast is not valid. (SqlManagerUI)

    ——————————
    BUTTONS:

    OK
    ——————————

    What I made wrong ?

    • Moved by

      Tuesday, June 1, 2010 4:20 PM
      Backup/restore problem (From:SQL Server Integration Services)

Answers

  • Do «RESTORE FILELISTONLY FROM DISK = N’E:ERPDW_31052010.bak'»  and adjust your RESTORE command’s MOVE options to match the files as indicated, so that the RESTORE command can create those files for you.


    Tibor Karaszi, SQL Server MVP | http://www.karaszi.com/sqlserver/default.asp | http://sqlblog.com/blogs/tibor_karaszi

    • Marked as answer by
      Alex Feng (SQL)
      Tuesday, June 8, 2010 11:25 AM

As I always say, Errors are a great source of learning and I am fortunate to have you as my readers. Because one of my blog reader reported an interesting issue which is worth blogging. This is his initial email:

Hi Pinal,
Your blogs have been very helpful to me to find solution of almost any SQL problem so far. This time, I am writing directly to see if you have time and provide some help to me.
I have a backup from database in SQL Server 2008 R2. When I want to restore this backup to SQL Server, I get this error: “Error: Specified cast is not valid. (SqlManagerUI)” How to I resolve this error?
Thanks!

We then exchanged various mails with screenshots, query, output and with his patience, we were able to find the cause of the issue. Here we go to what happened behind the scenes:

Here were the steps to restore the database:

SQL SERVER - Restore Error: Specified cast is not valid (SqlManagerUI) cast-error-01

As soon as OK was clicked, this was the error.

SQL SERVER - Restore Error: Specified cast is not valid (SqlManagerUI) cast-error-02

If we click on red cross icon at left bottom, we would see below

SQL SERVER - Restore Error: Specified cast is not valid (SqlManagerUI) cast-error-03

Here is the partial text of the message.

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)

As we can see above that SSMS is trying to populate the grid with the details about the backup. When I put profiler on my machine, it was running Restore Headeronly command on the selected file. So, I asked to run the command manually. You can refer my earlier blog for this SQL SERVER – Restore Database Backup using SQL Script (T-SQL)

When we ran the command, we found below

SQL SERVER - Restore Error: Specified cast is not valid (SqlManagerUI) cast-error-04

Above could be because of two reasons (which I found)

  1. Backup taken on SQL 2012 and Restore Headeronly was done in SQL 2008 R2
  2. Backup media is corrupted.

Solution of 1st one is easy – restore it on same or higher version. 2nd one is a difficult situation because you need to look for another good/restorable backup. In my case, it was first situation so we were good.

Another possible reason of “Specified cast is not valid” would be password protected backups. In such backups, headeronly would return “*** PASSWORD PROTECTED ***” in the first column as shown below.

SQL SERVER - Restore Error: Specified cast is not valid (SqlManagerUI) cast-error-05

So, next time you ever see any UI error, find the T-SQL statement by using profiler and run that directly to see “real” error message.

Have you ever come across situation where UI was giving some misleading error? Please comment and share your knowledge.

Reference: Pinal Dave (https://blog.sqlauthority.com)

Related Posts

Hey guys,

today I have an issue with SQL Server and to keep it short and simple: I’m getting the error message «specified cast is not valid» when trying to restore an SQL Database backup to a new and clean database.

Now I’ve read that this error usually pops up when you’re trying to restore a 2012 backup to SQL Server 2008. I don’t quite really understand it, but maybe you guys can simply confirm that the Server’s OS is also playing a role in this game, because the server’s OS was upgraded from Windows Server 2008 R2 to Windows Server 2012 R2, but it still has SQL Server 2008 R2 installed. Is the OS upgrade the cause for this or am I misunderstanding things?

I’ve created the .BAK file via Veeam Backup and Replication and chose a restore point from the beginning of this month, so the server’s OS was already 2012 R2 at that time, so the only solution would be to install SQL Server 2012, right?

Thanks in advance!

  • Remove From My Forums
  • Question

  • Environment is SCOM2012, patched to CU1.

    Went in this morning to add some new nodes to distribute our special SQL run-as account to some new computers recently added to monitoring. 

    Double-clicking the account in the console gives an immediate pop-up with the message:  ‘Specified cast is not valid’.  After I clear the message, my normal properties window appears but on the Distribution tab, all of my computers are gone (it’s
    blank).  I dare not add and save for fear of overwriting my list.  Has anyone seen this?  I’m not sure what would have caused this.  We have added and deleted a few computers in the last month but it’s been weeks since I last had to perform
    this operation.  The details of the message are below.  Thanks for any help.

    C

    ———————-

    Note:  The following information was gathered when the operation was attempted.  The information may appear cryptic but provides context for the error.  The application will continue to run.

    System.InvalidCastException: Specified cast is not valid.
       at Microsoft.EnterpriseManagement.Monitoring.Internal.MonitoringObjectGenerated.get_Id()
       at Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject.GetObjectWrappersPostProcessing[T](ReadOnlyCollection`1 resultSet, IEnterpriseManagementObjectCreatable`1 constructorHelper)
       at Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject.CreateMultiple[T](IList`1 dataAccessResultSet, EnterpriseManagementGroup managementGroup, Dictionary`2& instanceById, ObjectQueryOptions queryOptions)
       at Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject.CreateMultiple[T](IList`1 dataAccessResultSet, EnterpriseManagementGroup managementGroup, ObjectQueryOptions queryOptions)
       at Microsoft.EnterpriseManagement.SecurityConfigurationManagement.GetApprovedHealthServicesForDistribution[T](ISecuredData securedData)
       at Microsoft.EnterpriseManagement.Mom.Internal.UI.Common.SDKHelper.<>c__DisplayClass2b.<GetApprovedHealthServicesForDistribution>b__2a(Object sender, ConsoleJobEventArgs e)
       at Microsoft.EnterpriseManagement.Mom.Internal.UI.Console.ConsoleJobExceptionHandler.ExecuteJob(IComponent component, EventHandler`1 job, Object sender, ConsoleJobEventArgs args)

Answers

  • This problem is apparently fixed in UR5 for 2012 R2!

    http://support.microsoft.com/kb/3023138

    RunAs accounts cannot be edited because of «Specified cast is invalid» exception

    RunAs accounts can be distributed only to a selected computer through the distribution tab of Run As Account properties. When a computer that is in the distribution list is decommissioned from Operations Manager and the Run As account is opened, you receive
    the following exception, and no computers are shown on the list:

    System.InvalidCastException: Specified cast is not valid.    at Microsoft.EnterpriseManagement.Monitoring.Internal.MonitoringObjectGenerated.get_Id()

    Has anyone verified that this UR fixes the issue?

    • Proposed as answer by

      Wednesday, February 11, 2015 4:31 AM

    • Marked as answer by
      tx_cwf
      Wednesday, February 11, 2015 3:38 PM

  • Hello Jose,

    This exception comes in the console as a modal form.  The exception data is only what I’ve indicated at the beginning of this thread.  Clearing the exception allows operation to continue but when I get to the distribution list, it’s empty. 
    Yet I know the relationships are there because otherwise I’d get hundreds of alerts for credentials not distributed. 

    I was running the console on a management server and was unable to locate a corresponding eventlog event in either the operations Manager, system, or application logs on the MS.

    I’m going to have to rebuild my list at this point.  My DBA’s have been patiently standing by for some time now. 

    At best I can theorize that this was caused by one of the SQL Clusters we rebuilt (differently) without first removing the agentless and agent-based monitoring.

    Thanks for trying to help, Carl

    • Marked as answer by
      tx_cwf
      Thursday, July 26, 2012 3:14 PM

Понравилась статья? Поделить с друзьями:
  • Ошибка sparse file not allowed
  • Ошибка sp3 на котле аристон что означает
  • Ошибка sp3 на котле аристон что делать если
  • Ошибка sp3 на котле аристон причины
  • Ошибка sp3 на котле аристон как исправить ошибку