Strange problem with SQL CE UPDATE, (Specified cast is not valid) RRS feed

  • Question

  • Hello,

    I have very strange problem with sync framework when local CE database is updated with data fetched from SQL server. I have about ten tables, and all except one are working fine. I have traced the problem and all the deletes and inserts goes fine but updates fails in first statement. The error is following:

    Synchronization failed due to error at 16.11.2010 11:14:37. Specified cast is not valid.
    Source : Microsoft.Synchronization.Data.SqlServerCe
    Message : Specified cast is not valid.
    StackTrace :  at Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncUtil.BitConverterGetBytes(SETYPE seType, Object val, Int32& length)
      at Microsoft.Synchronization.Data.SqlServerCe.SqlCeClientSyncProvider.GetPKBlob(DataRow dr)
      at Microsoft.Synchronization.Data.SqlServerCe.SqlCeClientSyncProvider.ApplyUpserts(SyncTableMetadata tableMetadata, SyncTableProgress tableProgress, SyncGroupMetadata groupMetadata, DataTable dataTable, DataRowState applicableState, UInt64 lastSentAnchorValue, SyncSession syncSession)
      at Microsoft.Synchronization.Data.SqlServerCe.SqlCeClientSyncProvider.ApplyChanges(SyncGroupMetadata groupMetadata, DataSet dataSet, SyncSession syncSession)
      at Microsoft.Synchronization.SyncAgent.DownloadChanges(SyncGroupMetadata groupMetadata)
      at Microsoft.Synchronization.SyncAgent.DataSynchronize()
      at Microsoft.Synchronization.SyncAgent.Synchronize()
      at ***.Services.Synchronization.SynchronizationService.PerformSynchronization() in C:\Projects\**.cs:line 191
    No synchronization done by SynchronizationService.

    The update command is following:

    Using Command: UPDATE [tbRef_SalesPrice] SET [timestamp] = @P_540049004D0045005300540041004D0050000000, [Unit Price] = @P_55004E00490054002000500052004900430045000000, [Price Includes VAT] = @P_50005200490043004500200049004E0043004C00550044004500530020005600410054000000, [Allow Invoice Disc_] = @P_41004C004C004F005700200049004E0056004F00490043004500200044004900530043005F000000, [VAT Bus_ Posting Gr_ (Price)] = @P_56004100540020004200550053005F00200050004F005300540049004E0047002000470052005F00200028005000520049004300450029000000, [Ending Date] = @P_45004E00440049004E004700200044004100540045000000, [Allow Line Disc_] = @P_41004C004C004F00570020004C0049004E004500200044004900530043005F000000, [Item Category Code] = @P_4900540045004D002000430041005400450047004F0052005900200043004F00440045000000, [CreationDate] = @P_4300520045004100540049004F004E0044004100540045000000 WHERE [Item No_] = @P_4900540045004D0020004E004F005F000000 AND [Sales Type] = @P_530041004C0045005300200054005900500045000000 AND [Sales Code] = @P_530041004C0045005300200043004F00440045000000 AND [Starting Date] = @P_5300540041005200540049004E004700200044004100540045000000 AND [Currency Code] = @P_430055005200520045004E0043005900200043004F00440045000000 AND [Variant Code] = @P_560041005200490041004E005400200043004F00440045000000 AND [Unit of Measure Code] = @P_55004E004900540020004F00460020004D00450041005300550052004500200043004F00440045000000 AND [Minimum Quantity] = @P_4D0049004E0049004D0055004D0020005100550041004E0054004900540059000000 AND (__sysChangeTxBsn IS NULL    OR     (__sysChangeTxBsn in (select __sysTxBsn from __sysTxCommitSequence where __sysTxCsn < @P_5F005F0053005900530041004E00430048004F0052000000               )     )    OR     (__sysChangeTxBsn not in (select __sysTxBsn from __sysTxCommitSequence)        and      __sysChangeTxBsn < @P_5F005F0053005900530041004E00430048004F0052000000     )   ) ; 
    @P_5F005F0053005900530041004E00430048004F0052000000 Value: 0
    @P_540049004D0045005300540041004D0050000000 Len: 8 Value: 00-00-00-00-17-0D-72-AB
    @P_4900540045004D0020004E004F005F000000 Len: 10 Value: 613015-405
    @P_530041004C0045005300200054005900500045000000 Value: 1
    @P_530041004C0045005300200043004F00440045000000 Len: 9 Value: T.ESTONIA
    @P_5300540041005200540049004E004700200044004100540045000000 Len: 10 Value: 1753-01-01
    @P_430055005200520045004E0043005900200043004F00440045000000 Value: 
    @P_560041005200490041004E005400200043004F00440045000000 Value: 
    @P_55004E004900540020004F00460020004D00450041005300550052004500200043004F00440045000000 Len: 5 Value: 3-BAG
    @P_4D0049004E0049004D0055004D0020005100550041004E0054004900540059000000 Value: 1
    @P_55004E00490054002000500052004900430045000000 Value: 35,70000000000000000000
    @P_50005200490043004500200049004E0043004C00550044004500530020005600410054000000 Value: 0
    @P_41004C004C004F005700200049004E0056004F00490043004500200044004900530043005F000000 Value: 1
    @P_56004100540020004200550053005F00200050004F005300540049004E0047002000470052005F00200028005000520049004300450029000000 Value: 
    @P_45004E00440049004E004700200044004100540045000000 Len: 10 Value: 1753-01-01
    @P_41004C004C004F00570020004C0049004E004500200044004900530043005F000000 Value: 1
    @P_4900540045004D002000430041005400450047004F0052005900200043004F00440045000000 Len: 6 Value: 112321
    @P_4300520045004100540049004F004E0044004100540045000000 Value: 384409525

    When I compare the INSERT and UPDATE statements for this table, the values are exactly the same, so I start wondering if this is a bug in the implementation of Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncUtil when table contains multiple columns as PKs. The table structure is following:

    PK	Name	Datatype	Size	Identity	Nulls
    No	timestamp	varbinary(1)	1	No	Yes
    Yes	Item No_	nvarchar(20)	40	No	No
    Yes	Sales Type	int	4	No	No
    Yes	Sales Code	nvarchar(20)	40	No	No
    Yes	Starting Date	datetime	8	No	No
    Yes	Currency Code	nvarchar(10)	20	No	No
    Yes	Variant Code	nvarchar(10)	20	No	No
    Yes	Unit of Measure Code	nvarchar(10)	20	No	No
    Yes	Minimum Quantity	numeric(38,20)	17	No	No
    No	Unit Price	numeric(38,20)	17	No	No
    No	Price Includes VAT	tinyint	1	No	No
    No	Allow Invoice Disc_	tinyint	1	No	No
    No	VAT Bus_ Posting Gr_ (Price)	nvarchar(10)	20	No	No
    No	Ending Date	datetime	8	No	No
    No	Allow Line Disc_	tinyint	1	No	No
    No	Item Category Code	nvarchar(10)	20	No	No
    No	CreationDate	bigint	8	No	Yes

    Using Sync Framework 2.0. Microsoft.Synchronization.Data.SqlServerCe, 

    Any help is apreciated appreciated


    Tuesday, November 16, 2010 11:46 AM

All replies

  • Anyone?
    Friday, November 19, 2010 12:47 PM
  • I find out that following entry is written before the error happens: Client Delete-Server Update Conflict Detected and after that the specified cast is not valid is thrown by sync framework. Is sync framework trying to do something after the conflict is found, runing some query against the CE database?

    Tuesday, November 23, 2010 10:24 AM
  • must be doing a query as it needs to retrieve the conflicting row so it can be accessed in the ApplyChangeFailed event
    Tuesday, November 23, 2010 11:36 PM