locked
How to configure sync framework 2.1 so server wins conflicts RRS feed

  • Question

  • Hello!

    I am currently using sync framework version 2.1 to sync data between clients running a local database and a main MS SQL server.

     

    I understand that the conflict resolution operates when a row changes on both systems in between syncs by writing code for the applychngefailed events, as such:

    ((SqlCeSyncProvider)syncOrchestrator.LocalProvider).ApplyChangeFailed += new EventHandler<DbApplyChangeFailedEventArgs>(SyncSystem_ApplyChangeFailed);
          ((SqlSyncProvider)syncOrchestrator.RemoteProvider).ApplyChangeFailed +=new EventHandler<DbApplyChangeFailedEventArgs>(SyncSystem_RemoteApplyChangeFailed);
    

    And then the events look something like:

     

    void SyncSystem_ApplyChangeFailed(object sender, DbApplyChangeFailedEventArgs e)
        {
          if (e.Conflict.Type == DbConflictType.LocalUpdateRemoteUpdate)
          {
            e.Action = ApplyAction.Continue;
          }
        }
    
        
        //server wins
        void SyncSystem_RemoteApplyChangeFailed(object sender, DbApplyChangeFailedEventArgs e)
        {
          if (e.Conflict.Type == DbConflictType.LocalUpdateRemoteUpdate)
          {
            e.Action = ApplyAction.RetryWithForceWrite;
          }
        }
    

    What do I need to do, specifically, so that when a row changes on both systems the data from the server gets forced to the client?

     

    Thanks

     

    Tuesday, January 18, 2011 5:26 PM

Answers

  • typically you can set ApplyAction=Continue on the server provider and ApplyAtion=RetryWithForceWrite on the local ( or client ) provider to get the Server Wins scenario. for more details, please refer to this How-to on MSDN: http://msdn.microsoft.com/en-us/library/cc761628(v=sql.100).aspx for details and the code samples.

    thanks

    Yunwen


    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by Yunwen Bai Wednesday, January 19, 2011 8:04 AM
    Wednesday, January 19, 2011 8:04 AM

All replies

  • Hi, You could try setting the conflict resolution policy on the remote provider (corresp to the server) in the ProcessChangeBatch

    public override void ProcessChangeBatch (
    ConflictResolutionPolicy resolutionPolicy,
    ChangeBatch sourceChanges,
    Object changeDataRetriever,
    SyncCallbacks syncCallbacks,
    SyncSessionStatistics sessionStatistics
    )

    When server is the destination, provide ConflictResolutionPolicy.DestinationWins. This should make the server change to win, which should flow back to the client next time changes are sent to the client from the server.

     

    Sameer

    Tuesday, January 18, 2011 10:06 PM
  • typically you can set ApplyAction=Continue on the server provider and ApplyAtion=RetryWithForceWrite on the local ( or client ) provider to get the Server Wins scenario. for more details, please refer to this How-to on MSDN: http://msdn.microsoft.com/en-us/library/cc761628(v=sql.100).aspx for details and the code samples.

    thanks

    Yunwen


    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by Yunwen Bai Wednesday, January 19, 2011 8:04 AM
    Wednesday, January 19, 2011 8:04 AM