I’ve spend the last 8 months working with a customer in a really huge solution involving the Microsoft Sync Framework. Today one of the developers approached to me and asked a very simple question:
I created a local Sql Server Compact Edition file, copy all the rows from all the tables from a Sql Server database, so I assume both databases should have the same data. When I try to synchronize from my remote Sql Server to my local Sql Ce file I would expect no changes sent from the Sql Server to the Sql Ce file, but I realized the Sync Framework sent all the rows from all the tables and overwrite all the rows in the local Sql Ce file. What should I do to avoid this?
The Sync Framework is doing exactly what the Sql Ce provider expect to do, specially if the behaviour of the provider is to overwrite the changes, sending all the data. A way to avoid this problem is controlling the provisioning process and simply tell to the provision class not to populate the change tracking tables with the current data. There is an method in the Sql Server Provisioner class SqlSyncScopeProvisioning to control this, SetPopulateTrackingTableDefault, and accept a DbSyncCreationOption enum.
Well, the explanation of the enum options are very simple:
| DbSyncCreationOption | |
| CreateOrUseExisting | Populate the change tracking tables with current data, it will transfer current data from source to destination. (default option) |
| Skip | Do not populate the change tracking tables. It will not transfer the current data from source to destination |
If you use the Skip option the provisioning process won’t add the current data in the change tracking tables, but any new row or changed rows after the provisioning process will be of course tracked. That means, you won’t transfer current data from source to destination, that’s very useful if your Sql Ce file is an exact copy of your Sql Server database.
This answer in the MSDN Forums from June Tabadero explain the option a little more http://social.microsoft.com/Forums/sl-SI/syncdevdiscussions/thread/5ae739c0-d52d-458e-98f6-8d799aa97c55
I created a simple project to show you the behaviour of both options, just download it from bitbucket. https://bitbucket.org/cprieto/syncsample01
Note: Looks like now the Sync Framework Toolkit is Open Source!
