locked
Conflict resolver and ApplyAction RRS feed

  • Question

  • Hi,

    I would like to implement a simple resolver conflict.

    I take this sample : http://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=sync&ReleaseId=1200

    I subscribe to ApplyChangeFailed event on client and server providers and set ApplyChangeFailedEventArgs Action to specified states.

    But a don't have any effect when i use  ApplyAction.Continue and loop when i use ApplyAction.RetryWithForceWrite.

     

     

    What's wrong?


    Thanks

    • Moved by Hengzhe Li Friday, April 22, 2011 2:58 AM (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Thursday, May 28, 2009 7:18 AM

All replies

  • Could you clarify what you mean when you say that it doesn't have any effect?  Could you include the Adapter commands that you are using to update/insert your data?

    Thanks-
    Phil
    Thursday, May 28, 2009 7:20 PM
  • In fact,

    When i use ApplyAction.Continue, the server keep his value and the client too.

    My CRUD commands :

     

    // insert row command
    SqlCommand insOrderDetailsCmd = new SqlCommand();
    insOrderDetailsCmd.CommandType =
    CommandType.StoredProcedure;
    insOrderDetailsCmd.CommandText =
    "sp_order_details_applyinsert";
    insOrderDetailsCmd.Parameters.Add(
    "@order_id", SqlDbType.Int);
    insOrderDetailsCmd.Parameters.Add(
    "@order_details_id", SqlDbType.Int);
    insOrderDetailsCmd.Parameters.Add(
    "@product", SqlDbType.VarChar, 100);
    insOrderDetailsCmd.Parameters.Add(
    "@quantity", SqlDbType.Int);
    insOrderDetailsCmd.Parameters.Add(
    "@" + SyncSession.SyncClientIdHash, SqlDbType.Int);
    insOrderDetailsCmd.Parameters.Add(
    "@" + SyncSession.SyncLastReceivedAnchor, SqlDbType.Binary, 8);
    insOrderDetailsCmd.Parameters.Add(
    "@" + SyncSession.SyncRowCount, SqlDbType.Int).Direction = ParameterDirection.Output;

    adapterOrderDetails.InsertCommand = insOrderDetailsCmd;

     

    // update row command
    SqlCommand updOrderDetailsCmd = new SqlCommand();
    updOrderDetailsCmd.CommandType =
    CommandType.StoredProcedure;
    updOrderDetailsCmd.CommandText =
    "sp_order_details_applyupdate";
    updOrderDetailsCmd.Parameters.Add(
    "@order_id", SqlDbType.Int);
    updOrderDetailsCmd.Parameters.Add(
    "@order_details_id", SqlDbType.Int);
    updOrderDetailsCmd.Parameters.Add(
    "@product", SqlDbType.VarChar, 100);
    updOrderDetailsCmd.Parameters.Add(
    "@quantity", SqlDbType.Int);
    updOrderDetailsCmd.Parameters.Add(
    "@" + SyncSession.SyncClientIdHash, SqlDbType.Int);
    updOrderDetailsCmd.Parameters.Add(
    "@" + SyncSession.SyncLastReceivedAnchor, SqlDbType.Binary, 8);
    updOrderDetailsCmd.Parameters.Add(
    "@" + SyncSession.SyncRowCount, SqlDbType.Int).Direction = ParameterDirection.Output;

    adapterOrderDetails.UpdateCommand = updOrderDetailsCmd;


    The stored procedure :

    create procedure dbo.sp_order_details_applyinsert (
      @sync_last_received_anchor binary(8) ,
      @sync_client_id_hash int ,
      @sync_row_count int out,
            @order_id int = NULL ,
            @order_details_id int = NULL ,
            @product varchar(100) = NULL ,
            @quantity int = NULL )       
    as
     insert into [order_details] ([order_id], [order_details_id], [product], [quantity], [update_originator_id])
      values (@order_id, @order_details_id, @product, @quantity, @sync_client_id_hash)
     set @sync_row_count = @@rowcount 
    go



    create procedure dbo.sp_orders_applyupdate ( 
      @sync_last_received_anchor binary(8) ,
      @sync_client_id_hash int ,
      @sync_row_count int out,
            @order_id int,
            @order_date datetime = NULL )       
    as  
     update [orders]
         set [order_date] = @order_date,
             [update_originator_id] = @sync_client_id_hash
         where (update_timestamp <= @sync_last_received_anchor or update_originator_id = @sync_client_id_hash) and [order_id] = @order_id
     set @sync_row_count = @@rowcount
    go


    Thanks


    (Sorry for my english, i'm not fluent.)

    Tuesday, June 2, 2009 8:02 AM
  • Pit-

    For RetryWithForceWrite to work, there needs to be a parameter called @sync_force_write which should be used in your where clause:

    where (@sync_force_write = 1 OR (update_timestamp <= @sync_last_received_anchor ....

    What is the type on the column 'update_timestamp'?  Also, what is the type of anchor you are using?  Have you looked in the SQL Profiler to determine if the correct values are being passed in for the anchor parameter?

    Thanks-
    Wednesday, June 3, 2009 3:45 PM
  • Great, with the parameter @sync_force_write  the RetryWithForceWrite work but now the Apply.Continue loop into the EventHandler.

    The parameter must be into the server or into the client or the both stored procedure ?

    the column 'update_timestamp'  is timestamp
    the anchor is binary


    Is SQL Profiler exist in SQLExpress ?


    Thanks for your help Phil
    Friday, June 5, 2009 1:27 PM
  • SQL Express does not include the profiler, however I believe there are some free 3rd party tools that provide the same functionality.  You could also turn on tracing to get some debug info to see what is happening.  For how to enable tracing, see:
    http://msdn.microsoft.com/en-us/library/cc807160.aspx

    In the ApplyChangeFailedEvent, is it being raised for the same row over and over?  What does the ApplyChangeFailedEventArgs object show for its SyncConflict and Error properties?

    Thanks-
    Friday, June 5, 2009 4:12 PM
  • Yes the same row.

    {Microsoft.Synchronization.Data.SyncConflict}
    ClientChange: {order_details}
    ConflictType: ClientUpdateServerUpdate
    ErrorMessage: null
    ServerChange: {order_details}
    SyncStage: ApplyingUpdates

    Is the problem in the stored procedure or due to the datatype of update_timestamp and anchor?

    Thursday, June 11, 2009 1:26 PM
  • The issue could be either.  It's odd that it is the same row as when you choose Continue, internally the DbServerSyncProvider should move to the next row.  Is the row being repeated in the DataSet?
    Friday, June 12, 2009 8:21 PM