locked
Sync Framework 2.1 KeyNotFoundException RRS feed

  • Question

  • Hi,
        I have a synchronization scenario as below:

    Device Application SQL Server Compact 3.5 (Windows Mobile 5.0)
    Desktop Application SQL Server Compact 3.5
    Remote Database SQL Server 2008


                       OK                                Only desktop added data syncs
                                               (KeyNotFoundException for device added data)
    (Device CE) <--> (Desktop CE) <-------------------------------------------> (Remote SQL Server)

    My application creates a site database in the desktop application. A scope is then created between the desktop application database and the device database (CE to CE). Another scope is also created between the deskop database and the remote SQL Server database (CE to SQL). If I add data directly to my desktop application and sync with the remote database (Upload) the data syncs correctly. If I add data to my device application data syncs back to my desktop application correctly. If I then try and sync this new added data (from the device) back to the remote database from the desktop application I get a KeyNotFoundException. I think it happens in the 'ApplyingChanges' (Remote) event handler, my tables seem ok so I don't know if it is a system table where the error happens.

    System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
       at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
       at Microsoft.Synchronization.Data.SqlServer.SqlChangeHandler.ApplyBulkChanges(DataTable dataTable)
       at Microsoft.Synchronization.Data.RelationalSyncProvider.ApplyChangesInternal(DbSyncScopeMetadata scopeMetadata, IDbTransaction transaction, FailedDeleteDelegate_type failedDeleteDelegate, DataSet dataSet, ChangeApplicationType applyType)
       at Microsoft.Synchronization.Data.RelationalSyncProvider.ApplyChanges(DbSyncScopeMetadata scopeMetadata, IDbTransaction applyTransaction, DataSet dataSet, DbSyncSession DbSyncSession, Boolean commitTransaction, FailedDeleteDelegate_type failedDeleteDelegate, String batchFileName, ChangeApplicationAction& action)
       at Microsoft.Synchronization.Data.RelationalSyncProvider.SingleTransactionApplyChangesAdapter.Apply(DataSet dataSet, Boolean commitTransaction, FailedDeleteDelegate_type failedDeleteDelegate, String batchFileName, ChangeApplicationAction& action)
       at Microsoft.Synchronization.Data.RelationalSyncProvider.ApplyChanges(DbSyncScopeMetadata scopeMetadata, DataSet dataSet, DbSyncSession dbSyncSession, Boolean commitTransaction)
       at Microsoft.Synchronization.Data.RelationalSyncProvider.ProcessChangeBatch(ConflictResolutionPolicy resolutionPolicy, ChangeBatch sourceChanges, Object changeDataRetriever, SyncCallbacks syncCallbacks, SyncSessionStatistics sessionStatistics)
       at Microsoft.Synchronization.KnowledgeProviderProxy.ProcessChangeBatch(CONFLICT_RESOLUTION_POLICY resolutionPolicy, ISyncChangeBatch pSourceChangeManager, Object pUnkDataRetriever, ISyncCallback pCallback, _SYNC_SESSION_STATISTICS& pSyncSessionStatistics)
       at Microsoft.Synchronization.CoreInterop.ISyncSession.Start(CONFLICT_RESOLUTION_POLICY resolutionPolicy, _SYNC_SESSION_STATISTICS& pSyncSessionStatistics)
       at Microsoft.Synchronization.KnowledgeSyncOrchestrator.DoOneWaySyncHelper(SyncIdFormatGroup sourceIdFormats, SyncIdFormatGroup destinationIdFormats, KnowledgeSyncProviderConfiguration destinationConfiguration, SyncCallbacks DestinationCallbacks, ISyncProvider sourceProxy, ISyncProvider destinationProxy, ChangeDataAdapter callbackChangeDataAdapter, SyncDataConverter conflictDataConverter, Int32& changesApplied, Int32& changesFailed)
       at Microsoft.Synchronization.KnowledgeSyncOrchestrator.DoOneWayKnowledgeSync(SyncDataConverter sourceConverter, SyncDataConverter destinationConverter, SyncProvider sourceProvider, SyncProvider destinationProvider, Int32& changesApplied, Int32& changesFailed)
       at Microsoft.Synchronization.KnowledgeSyncOrchestrator.Synchronize()
       at Microsoft.Synchronization.SyncOrchestrator.Synchronize()
       at Protex_Expert.fmMain.bgwRemoteSync_DoWork(Object sender, DoWorkEventArgs e) in d:\MyAppFolder\fmMain.cs:line 22964
       at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)
       at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)

    Any help appreciated.

    Thanks
    Paul.


    Paul Wainwright

    Thursday, November 6, 2014 3:48 PM

Answers

  • Hi,
        I have a synchronization scenario as below:

    Device Application SQL Server Compact 3.5 (Windows Mobile 5.0)
    Desktop Application SQL Server Compact 3.5
    Remote Database SQL Server 2008


                       OK                                Only desktop added data syncs
                                               (KeyNotFoundException for device added data)
    (Device CE) <--> (Desktop CE) <-------------------------------------------> (Remote SQL Server)

    My application creates a site database in the desktop application. A scope is then created between the desktop application database and the device database (CE to CE). Another scope is also created between the deskop database and the remote SQL Server database (CE to SQL). If I add data directly to my desktop application and sync with the remote database (Upload) the data syncs correctly. If I add data to my device application data syncs back to my desktop application correctly. If I then try and sync this new added data (from the device) back to the remote database from the desktop application I get a KeyNotFoundException. I think it happens in the 'ApplyingChanges' (Remote) event handler, my tables seem ok so I don't know if it is a system table where the error happens.

    System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
       at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
       at Microsoft.Synchronization.Data.SqlServer.SqlChangeHandler.ApplyBulkChanges(DataTable dataTable)
       at Microsoft.Synchronization.Data.RelationalSyncProvider.ApplyChangesInternal(DbSyncScopeMetadata scopeMetadata, IDbTransaction transaction, FailedDeleteDelegate_type failedDeleteDelegate, DataSet dataSet, ChangeApplicationType applyType)
       at Microsoft.Synchronization.Data.RelationalSyncProvider.ApplyChanges(DbSyncScopeMetadata scopeMetadata, IDbTransaction applyTransaction, DataSet dataSet, DbSyncSession DbSyncSession, Boolean commitTransaction, FailedDeleteDelegate_type failedDeleteDelegate, String batchFileName, ChangeApplicationAction& action)
       at Microsoft.Synchronization.Data.RelationalSyncProvider.SingleTransactionApplyChangesAdapter.Apply(DataSet dataSet, Boolean commitTransaction, FailedDeleteDelegate_type failedDeleteDelegate, String batchFileName, ChangeApplicationAction& action)
       at Microsoft.Synchronization.Data.RelationalSyncProvider.ApplyChanges(DbSyncScopeMetadata scopeMetadata, DataSet dataSet, DbSyncSession dbSyncSession, Boolean commitTransaction)
       at Microsoft.Synchronization.Data.RelationalSyncProvider.ProcessChangeBatch(ConflictResolutionPolicy resolutionPolicy, ChangeBatch sourceChanges, Object changeDataRetriever, SyncCallbacks syncCallbacks, SyncSessionStatistics sessionStatistics)
       at Microsoft.Synchronization.KnowledgeProviderProxy.ProcessChangeBatch(CONFLICT_RESOLUTION_POLICY resolutionPolicy, ISyncChangeBatch pSourceChangeManager, Object pUnkDataRetriever, ISyncCallback pCallback, _SYNC_SESSION_STATISTICS& pSyncSessionStatistics)
       at Microsoft.Synchronization.CoreInterop.ISyncSession.Start(CONFLICT_RESOLUTION_POLICY resolutionPolicy, _SYNC_SESSION_STATISTICS& pSyncSessionStatistics)
       at Microsoft.Synchronization.KnowledgeSyncOrchestrator.DoOneWaySyncHelper(SyncIdFormatGroup sourceIdFormats, SyncIdFormatGroup destinationIdFormats, KnowledgeSyncProviderConfiguration destinationConfiguration, SyncCallbacks DestinationCallbacks, ISyncProvider sourceProxy, ISyncProvider destinationProxy, ChangeDataAdapter callbackChangeDataAdapter, SyncDataConverter conflictDataConverter, Int32& changesApplied, Int32& changesFailed)
       at Microsoft.Synchronization.KnowledgeSyncOrchestrator.DoOneWayKnowledgeSync(SyncDataConverter sourceConverter, SyncDataConverter destinationConverter, SyncProvider sourceProvider, SyncProvider destinationProvider, Int32& changesApplied, Int32& changesFailed)
       at Microsoft.Synchronization.KnowledgeSyncOrchestrator.Synchronize()
       at Microsoft.Synchronization.SyncOrchestrator.Synchronize()
       at Protex_Expert.fmMain.bgwRemoteSync_DoWork(Object sender, DoWorkEventArgs e) in d:\MyAppFolder\fmMain.cs:line 22964
       at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)
       at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)

    Any help appreciated.

    Thanks
    Paul.


    Paul Wainwright


    Removing rows in

    Orchestrator_ChangesSelected causing the problem.


    Paul Wainwright

    • Marked as answer by pr_wainwright Tuesday, November 11, 2014 12:54 PM
    Tuesday, November 11, 2014 12:54 PM

All replies

  • Hi,
        I have a synchronization scenario as below:

    Device Application SQL Server Compact 3.5 (Windows Mobile 5.0)
    Desktop Application SQL Server Compact 3.5
    Remote Database SQL Server 2008


                       OK                                Only desktop added data syncs
                                               (KeyNotFoundException for device added data)
    (Device CE) <--> (Desktop CE) <-------------------------------------------> (Remote SQL Server)

    My application creates a site database in the desktop application. A scope is then created between the desktop application database and the device database (CE to CE). Another scope is also created between the deskop database and the remote SQL Server database (CE to SQL). If I add data directly to my desktop application and sync with the remote database (Upload) the data syncs correctly. If I add data to my device application data syncs back to my desktop application correctly. If I then try and sync this new added data (from the device) back to the remote database from the desktop application I get a KeyNotFoundException. I think it happens in the 'ApplyingChanges' (Remote) event handler, my tables seem ok so I don't know if it is a system table where the error happens.

    System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
       at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
       at Microsoft.Synchronization.Data.SqlServer.SqlChangeHandler.ApplyBulkChanges(DataTable dataTable)
       at Microsoft.Synchronization.Data.RelationalSyncProvider.ApplyChangesInternal(DbSyncScopeMetadata scopeMetadata, IDbTransaction transaction, FailedDeleteDelegate_type failedDeleteDelegate, DataSet dataSet, ChangeApplicationType applyType)
       at Microsoft.Synchronization.Data.RelationalSyncProvider.ApplyChanges(DbSyncScopeMetadata scopeMetadata, IDbTransaction applyTransaction, DataSet dataSet, DbSyncSession DbSyncSession, Boolean commitTransaction, FailedDeleteDelegate_type failedDeleteDelegate, String batchFileName, ChangeApplicationAction& action)
       at Microsoft.Synchronization.Data.RelationalSyncProvider.SingleTransactionApplyChangesAdapter.Apply(DataSet dataSet, Boolean commitTransaction, FailedDeleteDelegate_type failedDeleteDelegate, String batchFileName, ChangeApplicationAction& action)
       at Microsoft.Synchronization.Data.RelationalSyncProvider.ApplyChanges(DbSyncScopeMetadata scopeMetadata, DataSet dataSet, DbSyncSession dbSyncSession, Boolean commitTransaction)
       at Microsoft.Synchronization.Data.RelationalSyncProvider.ProcessChangeBatch(ConflictResolutionPolicy resolutionPolicy, ChangeBatch sourceChanges, Object changeDataRetriever, SyncCallbacks syncCallbacks, SyncSessionStatistics sessionStatistics)
       at Microsoft.Synchronization.KnowledgeProviderProxy.ProcessChangeBatch(CONFLICT_RESOLUTION_POLICY resolutionPolicy, ISyncChangeBatch pSourceChangeManager, Object pUnkDataRetriever, ISyncCallback pCallback, _SYNC_SESSION_STATISTICS& pSyncSessionStatistics)
       at Microsoft.Synchronization.CoreInterop.ISyncSession.Start(CONFLICT_RESOLUTION_POLICY resolutionPolicy, _SYNC_SESSION_STATISTICS& pSyncSessionStatistics)
       at Microsoft.Synchronization.KnowledgeSyncOrchestrator.DoOneWaySyncHelper(SyncIdFormatGroup sourceIdFormats, SyncIdFormatGroup destinationIdFormats, KnowledgeSyncProviderConfiguration destinationConfiguration, SyncCallbacks DestinationCallbacks, ISyncProvider sourceProxy, ISyncProvider destinationProxy, ChangeDataAdapter callbackChangeDataAdapter, SyncDataConverter conflictDataConverter, Int32& changesApplied, Int32& changesFailed)
       at Microsoft.Synchronization.KnowledgeSyncOrchestrator.DoOneWayKnowledgeSync(SyncDataConverter sourceConverter, SyncDataConverter destinationConverter, SyncProvider sourceProvider, SyncProvider destinationProvider, Int32& changesApplied, Int32& changesFailed)
       at Microsoft.Synchronization.KnowledgeSyncOrchestrator.Synchronize()
       at Microsoft.Synchronization.SyncOrchestrator.Synchronize()
       at Protex_Expert.fmMain.bgwRemoteSync_DoWork(Object sender, DoWorkEventArgs e) in d:\MyAppFolder\fmMain.cs:line 22964
       at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)
       at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)

    Any help appreciated.

    Thanks
    Paul.


    Paul Wainwright


    Removing rows in

    Orchestrator_ChangesSelected causing the problem.


    Paul Wainwright

    • Marked as answer by pr_wainwright Tuesday, November 11, 2014 12:54 PM
    Tuesday, November 11, 2014 12:54 PM
  • Hi Wainwright,

    Could you please share how you solved this problem and what is the root cause. We are also experiencing similar issue on our sync system.

    Thanks,

    Sai

    Tuesday, December 30, 2014 1:48 PM
  • Sai,

         Sorry for the delay in my reply. Just returned to work from Christmas holidays. I managed to get the 'KeyNotFoundException' while experimenting with subsets of SQL Server CE data. I wanted to achieve synchronization using filters between SQL Server CE & SQL Server CE databases but this is not supported. I tried synchronizing the full databases then deleting data on one database, making my changes then syncing back the data. In my 'Orchestrator_ChangesSelected' I think I was trying to remove rows that no longer existed. I used the below code to check each row first:

    DataRow row = dataTable.Rows[j];

    //Stop 'VersionNotFoundException', 'There is no current data to access' Exception
    if (row.HasVersion(DataRowVersion.Current))
    {

    ...

    }

    if (row.RowState == DataRowState.Added)
    {

    ...

    }

    Regards

    Paul.


    Paul Wainwright

    Monday, January 5, 2015 9:15 AM