locked
Managing concurency conflicts on Sync Framework RRS feed

  • General discussion

  • Hi,
       I´m currently using sync framework 2.0, togehter with sql server 2008 Express, in order to be able to synchronize DBs. The providers i use are the SqlSyncProviders available in MSF. In order to manage concurrency conflicts i´ve implemented the event  ApplyChangeFailed which looks like:

       /// <summary>
        /// Conflict violation management event.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void sqlRemoteProv_ApplyChangeFailed(object sender, DbApplyChangeFailedEventArgs e)
        {
          if (e.Conflict.Type == DbConflictType.LocalUpdateRemoteUpdate)
          {
            e.Action = ApplyAction.RetryWithForceWrite;
          }

          if (e.Conflict.Type == DbConflictType.LocalUpdateRemoteDelete)
          {
            e.Action = ApplyAction.RetryWithForceWrite;
          }

          if (e.Conflict.Type == DbConflictType.LocalDeleteRemoteDelete)
          {
            e.Action = ApplyAction.Continue;
          }

          if (e.Conflict.Type == DbConflictType.LocalDeleteRemoteUpdate)
          {
            e.Action = ApplyAction.RetryWithForceWrite;
          }

          if (e.Conflict.Type == DbConflictType.LocalInsertRemoteInsert)
          {
            e.Action = ApplyAction.RetryWithForceWrite;
          }

          if (e.Conflict.Type == DbConflictType.ErrorsOccurred)
          {
            if (e.Error != null && e.Error.Message.Contains("FOREIGN KEY"))
            {
              e.Action = ApplyAction.RetryNextSync;
              needSyncIteration = true;
            }
            else
            {
              e.Action = ApplyAction.RetryWithForceWrite;
            }
          }

          //Write info in the log file.
          string errorMsg = "CONCURRENCY VIOLATION in SqlExpress DB Synchronizer. VIOLATION TYPE: " +
                      e.Conflict.Type.ToString() + " ACTION: " + e.Action.ToString();

          if (e.Error != null)
          {
            errorMsg += " ERROR: " + e.Error.Message;
          }

          Logger.Instance.Log(errorMsg);
        }

    The problem i´m having is that in case the action RetryWithForceWrite is used, i don´t know where to add logic to handle this conflict. I mean, in the help text of this Action says that the logic should be included in the synchronizatoin adapter commands, but i haven´t defined any synchronization Adapter since the SqlSyncProviders are being used in this case. Perhaps i´m missing something here, maybe the conflict resolution shouldn´t be implemented in this way when using those providers, should it?
    It will be great if you can provide me a simple example...

    Thanks in advance,
    Paola
    Wednesday, November 4, 2009 9:23 PM