Bidirectional Deletes Fail RRS feed

  • Question

  • Hi Everyone-


    I have used the Local Database Cache Wizard in Visual Studio 2008 in order to setup my ocassionally connected application. My server side runs out of SQL Server Express 2005. I made the appropriate changes in the Partial Class of the SyncAgent in order to allow for BiDirectional Synchronization. Howerver, I have a problem with BiDirectional DELETES. Suppose I have two tables (Orders & Order Details, i.e. Parent and Child). If I delete an Order and all its Order Details, I observere the following behaviour: Following synchronization, the Order Details are deleted as expected but the Order parent is not (leaving me with in orphan parent in the Server Database :-( ....) I have set up referential integrity constraints on my client DataSet....(I tried using cascading deletes with the same result).


    Please, any help will be much appreciated.






    • Moved by Max Wang_1983 Friday, April 22, 2011 8:01 PM forum consolidation (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Wednesday, April 16, 2008 9:58 PM

All replies

  • Hello Cristobal,


    There are few things you can check.


    1. Make sure that "Order" table is added as a SyncTable object to the SyncAgent before "Order Details".

    2. Make a simple delete on the server side.

    3. Turn on Profiler to capture the Delete Enumeration on the server side.  This is going to see if DELETED rows are enumerated properly by the SelectIncrementalDelete Command (one for each table).

    4. Subscribe to ApplyingChanges event from SqlCeClientSyncProvider object and check whether the deleted rows (from "Orders" are contained in the e.Changes.Tables ["Orders"].Rows.

    5. Subscribe to ApplyChangeFailed event from SqlCeClientSyncProvider object as well to check whether we have a conflict during DELETE.



    Wednesday, April 16, 2008 11:32 PM
  • Thanks for your kind help L Zhou. I will look into 1,3,4,5 tonight and report back. I really appreciate the help.

    Thursday, April 17, 2008 12:45 AM
  • Im back!


    L Zhou I tried your suggestions with the following results:


    -I could not figure out how to change the order of the SyncTables in the SyncAgent. I tried clearing the collection and then adding the Parent first followed by the Child,  but the deletes still did not cascade. Also, I was able to verify with the OnInitialized event that the Parent is indeed indexed before the Child in the SyncTable collection. So apparently the default order should work for me.....how do you overwrite it anyhow?


    - With the AppliedChangesFailed event I discovered every time I add a new Order (Parent) or OrderDetail (Child) to the Client and try to Synchronize I get a Primary Key conflict for both tables ( the system argues that the key values are not unique). Note that for my Primary keys i am using  GUIDs and I assign them on the TableNewRow event of each table in the dataset.  Why do you think its picking up this confilct?


    - With the ApplyingChanges event it seems like the Orders rows to be deleted are in there.


    - The ONLY way i could get the Deletes to cascade through Parent and Child was to set both of their syncgroups to a syngroup "mygroup" that I defined in the OnInitialized event.


    Again, thanks a lot for the help...I think I'm close but not yet there :-)





    Thursday, April 17, 2008 2:24 AM
  • Hello Cristobal,


    Let us try to wrap up what we had -

    1. Sync Table objects were added correctly in the SyncAgent, by the desired order, Parent table is followed by Child table.  SyncGroup object is defined to link the parent table and child table.  So Data from these two tables are processed in one transaction.

    2. ApplyingChanges (on the Client Provider) contains the DELETED rows in the dataset.  In another word, DELETE is enumerated properly from the Server table.

    3. AppliedChangesFailed (on the Client Provider) due to some kind of conflict.


    DELETE is working now, right?


    Sorry more questions:

    1. What kind of conflict type did you see in the  AppliedChangesFailed (client provider) handler?

    2. Is GUID the primary key on the server tables as well?

    3. Are you modifying the DataSet during Sync?  Are you sure you use different GUID values as Primary Keys?

    4. Can you provide a bit more details on how you add this new table row to the dataset table?  Under what sync stage?



    Friday, April 18, 2008 12:34 AM