none
Sync Framework is deleting a record on sync RRS feed

  • Question

  • Background on my application...  Using SyncFx 2.1 and syncing between SQL CE and SQL Server 2008 R2.  I am using filtered scopes to load the CE database.

    In certain scenarios, SyncFx is deleting a Job record from the server on sync.  Any guidance on this issue would be awesome.

    Quick course on my db...

    CustomerLocation has many ContractHeader has many Job

    I guess I should start with my filter statement on the Job table...

    side.ContractID in (select ContractID from ContractHeader where CustLocID in (select CustLocID from CustomerLocation where BranchID = @branchId) and ContractStatusID in (2,4,5) and DATEDIFF(d, getdate(), ContractEndDt) > -15) and DATEDIFF(d, getdate(), SchedInspDt) between -400 and 45

    When executing this statement against the db it does return the record in question.

    Upon sync, the job record is deleted off the server. I have selects from the server pre and post sync, if anyone would like to see them.  

    The client side DB does have this remnant in the tracking table...

    JobId sync_row_is_tombstone sync_create_peer_timestamp sync_update_bsn last_change_datetime
    3311 1 9278625 58079 2013-04-24 14:10:33.787

    If anyone could tell me what I am doing wrong, that would be very helpful.

    Wednesday, April 24, 2013 2:50 PM

Answers

  • Think I figured this out.  The Job exists on the server but does not sync until its SchedInspDt is in the correct range.  So the record comes down as an update.  Since the client has never seen this record before, and it is coming as an update,  SyncFX assumes it was deleted locally and tombstones cleaned up, so it raises a conflict.

    Conflict resolution is local wins, so it creates a tombstone.  

    I believe I will have to set the resolution to remote wins, or change the way I filter.  

    Wednesday, May 1, 2013 9:18 PM

All replies

  • sync fx will not delete a record on the destination unless the source sends it a deleted row.

    have you checked for conflicts occurring in your sync? are you updating PKs?

    Wednesday, April 24, 2013 3:34 PM
    Moderator
  • We are not updating PKs. 

    I have turned on some logging during the sync process and I get this...

    Scope: Job-Dayton
    StartTime: 4/24/2013 10:10:32 AM
    EndTime: 4/24/2013 10:10:35 AM
    DownloadChangesApplied: 1
    DownloadChangesFailed: 1
    DownloadChangesTotal: 2
    UploadChangesApplied: 1
    UploadChangesFailed: 0
    UploadChangesTotal: 1

    I am guessing the DownloadChangesFailed returning a 1 is the culprit?  How can I check further what this means?

    Wednesday, April 24, 2013 4:43 PM
  • subscribe to the ApplyChangeFailed event
    Thursday, April 25, 2013 1:37 AM
    Moderator
  • Thanks for the response JuneT, here are my findings so far...

    My Job scope has two tables inside.  Job and JobInspectorXRef.  They are defined in such a way that Job should sync before JobInspectorXRef.  JobInspectorXRef has a reference to the Job table via a foreign key (JobId).

    At the point where I start to Sync the Job scope,  The ApplyChangeFailed event fires and it is reporting that the insertion of the JobInspectorXRef is failing, because the corresponding Job record has not been inserted.  And that is correct, the Job record is not there.  First question is why not?  I believe I have defined my scope such that Job should sync before JobInspectorXRef

    ApplyChangeFailed fires a second time with a Conflict Type of LocalCleanedupDeleteRemoteUpdate.

    Finally, there is a call made to proxy.ApplyChanges and my corresponding Job and JobInspectorXRef job is deleted off the server.  

    What am I doing wrong?

    Wednesday, May 1, 2013 5:26 PM
  • OK, tried a few more things.

    Made a job without assigning an inspector.  During the sync, I only get the ApplyChangeFailed event fired once.  The one with the Conflict Type of LocalCleanedupDeleteRemoteUpdate.

    We can assume the first ApplyChangeFailed event in the previous post is secondary to the bigger problem, the job record is never inserted.  A job_tracking record is inserted with it's sync_row_is_tombstone flag set. 

    The end result is the same, the job record is deleted off the server.

    Wednesday, May 1, 2013 8:24 PM
  • Think I figured this out.  The Job exists on the server but does not sync until its SchedInspDt is in the correct range.  So the record comes down as an update.  Since the client has never seen this record before, and it is coming as an update,  SyncFX assumes it was deleted locally and tombstones cleaned up, so it raises a conflict.

    Conflict resolution is local wins, so it creates a tombstone.  

    I believe I will have to set the resolution to remote wins, or change the way I filter.  

    Wednesday, May 1, 2013 9:18 PM