Symptoms
Consider the following scenario:
-
You create an application that uses Microsoft Sync Framework 2.1 to perform database synchronization on a computer.
-
You configure the application to use batching for the delivery of changes.
-
The application uses a handler to perform some actions if the ChangesApplied event is fired and if the DbSyncContext.IsLastBatch property is set to True.
-
A change fails in one of the tables that are synchronized because of a constraint violation.
-
The failed change operation is put in a retry queue.
In this scenario, a ChangesApplied event incorrectly occurs before the failed change is applied.
For example, table A contains a primary key that is referenced by table B as a foreign key. When a delete operation for a row in table A arrives in a batch and a delete operation for table B arrives in another batch, the delete operation in table A fails. The operation may fail because of a foreign key violation. The delete operation in table A is put in a retry queue. However, the ChangesApplied event is incorrectly called before all the failed changes that are in the retry queue are applied. Therefore, the business logic is broken in the ChangesApplied event.
Resolution
To resolve this issue, apply the following cumulative update.
After you apply this update, the ChangesApplied event is called only if all changes that are in the retry queue are applied to a database.
Cumulative update
The hotfix for this issue was first released in Sync Framework 2.1 build 2.1.2503.00. For more information about how to obtain this hotfix package, click the following article number to view the article in the Microsoft Knowledge Base:
2531321 Description of the hotfixes that are released in Sync Framework 2.1 build 2.1.2503.00 Note Because the builds are cumulative, each new hotfix release contains all the hotfixes that were included in the previous Sync Framework 2.1 hotfix release. We recommend that you consider applying the most recent hotfix release that contains this hotfix. For more information about the builds that were released after Sync Framework 2.1 was released, click the following article number to view the article in the Microsoft Knowledge Base:
2531326 Description of the Sync Framework 2.1 builds that were released after Sync Framework 2.1 was released
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.
Workaround
To work around this issue, do not use batching in the application.
References
For more information about how to deliver changes in batches, visit the following MSDN website:
How to deliver changes in batchesFor more information about how to use events and to program business logic, visit the following MSDN website: