Conflicts, Identity Columns and Data Synchronization

During the "Defy Occasionally-Connected Challenges With Smart Client Applications" presentation of the Heroes Happen Here tour, we touch upon how to leverage Microsoft Data Synchronization services via the new local data cache wizard in Visual Studio 2008.  Unfortunately, we don't get to talk much about how the synchronization actually transpires, how to handle data conflicts, best practices for dealing with identity columns, etc.

To get finer grained control over the synchronization steps, note that the ClientSyncProvider and ServerSyncProvider classes are defined as partial classes within the code generated from the Local Database Cache configuration wizard in Visual Studio 2008.  Those classes expose several events such as ApplyingChanges and ApplyChangeFailed for which you can add event handlers to provide additional processing and conflict resolution logic.  For details, check out the MSDN topic "How To: Handle Data Conflicts and Errors."

Identity columns provide additional challenges in certain types of synchronization scenarios since the uniqueness of the key value cannot be guaranteed across all of the nodes participating in the synchronization.  A GUID (uniqueidentifier) column doesn't have the same drawbacks, and other options are also available depending on the particular application requirements.  See Selecting an Appropriate Primary Key for a Distributed Environment (Sync Services) for an overview of several choices you might consider.