locked
Prevent specific changes from getting synchronized RRS feed

  • Question

  • Is it possible to prevent certain inserts made to a table on mobile client from getting inserted on the server?

    I was tried deleting the inserts from the delta table within the clientSyncProvider_ChangesSelected event by getting hold of the table from ChangesSelectedEventArgs, but it seems after I do that, all the other edits/updates in that delta table are NOT applied on the server.

    Thanks

    Apurv
    • Moved by Hengzhe Li Friday, April 22, 2011 6:38 AM (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Thursday, December 11, 2008 6:16 PM

All replies

  • Hi Apurv

    I assume that you use sqlserver compact as your client datastore:

    In this case, after applying non sync services changes on the client db, call the appropriate AcceptChanges(...) method overload on your SqlCeClientSyncProvider  object.


    Monday, December 15, 2008 8:23 AM
  • Thank you so much for your reply! 

    Yes I am using SQL CE 3.5 as client database. I want to collect all the inserts made on the client in the delta table so that I can apply custom business logic to them but I dont want to insert them on server using sync services. However I do  want the sync services to apply deletes and updates on the client to the server. 

    If I call AcceptChanges(), I assume that it will remove all the deletes and updates in the delta table as well? 

    Thanks

    Monday, December 15, 2008 2:28 PM
  • If I understand correctly, you want to do the following:

    1. Let your user make changes to the client table(s)
    2. Get a list of all changes made by your user (updates, deletes, inserts)
    3. Do some client side processing for all inserts
    4. Apply client changes on the server, but only the updates and deletes

    According to my understanding, this is not a scenario currently supported with SyncronizationServices, as AcceptChanges does not distinguish between updates, inserts and deletes.

    However, if you do not find a better solution, you could get away with the following (referencing the steps above)

    2. Get a Dataset by calling GetChanges() that represents all changes since the last synchronization or call to AcceptChanges()
    3. Find all inserts in the Dataset and do the processing
    4.1 Delete all inserts in the client db (Using the knowledge in the dataset)
    4.2 Synchronize (Will synchronize updates and deletes. Not the inserts, as they have been deleted in step 4.1)
    4.3 (If you still need the inserted records on the client, reinsert them in the client db)
    4.4 Call AcceptChanges(...) if step 4.3 is required

    Alternatively, you would have to modify the internal change tracking columns in the client db which is not to bright an idea as they are not part of the official API and can change with every new release of sync services.
    Tuesday, December 16, 2008 6:21 PM
  • Yes thats the exact workflow that I intend to follow. The custom logic that I am doing with inserts is this:

    1. So if the user edits a row in the table, the application deletes the original row and recreates it with different primary key (integer) due to the application needs.

    2. Get a Dataset by calling GetChanges() that represents all changes since the last synchronization or call to AcceptChanges()

    This is exactly what I am doing right before synchronization. I grab all the inserts of new rows created in step 1.

    3. Find all inserts in the Dataset and do the processing

    THATS WHAT I DO. HOWEVER I AM FINDING ALL THE INSERTS AND THEN USING A CUSTOM WEB SERVICE TO INSERT THE SAME ON SERVER BECAUSE THE PRIMARY KEY FOR THIS TABLE IS INTEGER.

    4.1 Delete all inserts in the client db (Using the knowledge in the dataset)

    THATS WHAT I DO. I ALSO DELETE THE INSERTS ON CLIENT SO THAT THEY ARE NOT SYNCHED IN NEXT STEP

    4.2 Synchronize (Will synchronize updates and deletes. Not the inserts, as they have been deleted in step 4.1)


    THIS STEP HOWEVER IS FAILING FOR ME. I AM GETTING THE CLIENT DELETE SERVER UPDATE CONFLICT ON THE DELETEs of the original row in step 1 on the server side.

    Thanks

    Apurv
    Wednesday, December 17, 2008 2:34 AM
  • This sounded like an easy problem first ;-)

    OK, I think the real cause of the problem is using a webservice which does also manipulate the server side data

    (THATS WHAT I DO. HOWEVER I AM FINDING ALL THE INSERTS AND THEN USING A CUSTOM WEB SERVICE TO INSERT THE SAME ON SERVER BECAUSE THE PRIMARY KEY FOR THIS TABLE IS INTEGER.)

    Is the reason for your inserting the rows over a web service that you need the rows to have a application wide unique integer id? If not, what is the reason to do updates in the database both by using sync services and your own code?

    In our project, we absolutely avoid changing rows one time using sync services, and web services, as you are bound to end up with conflicts!
    Wednesday, December 17, 2008 1:48 PM
  • Thank you so much for reply Oliver. Yes the reason for using web service is because the table has integer type as the primary key and its not possible to use sync services for the inserts since the primary key values on SQL CE for newly inserted rows are not unique on the server.

    We are then potentially thinking of doing the updates and deletes also using the custom web service. However I do not understand why the server wants to update the row which has been deleted by the client.

    Thanks
    Wednesday, December 17, 2008 2:21 PM
  • Any idea on why does the server throw ClientDeleteServerUpdate conflict on the row that is deleted on client.
    Thanks
    Wednesday, December 17, 2008 8:14 PM
  • To prevent conflicts, I strongly suggest you make different use of webservices:

    • Use the webservice to get your unique integer id from the server, then insert a new row on the client using the unique integer id.
    • Let synchronization services handle the required updates of your server database (Not a custom webservice)

    Monday, December 22, 2008 8:15 AM
  • So instead of using web services to insert on server (online insertion?), I do the other way round?

    At the time of insertion of new row, user is in disconnected state and its not possible to get the new id from the server at that point.

    Btw-yes I have dropped the idea of performing updates using web service.

    Thanks a lot
    Monday, December 22, 2008 3:48 PM
  • Hmmmmm if user is in disconnected state on the time of row creation, I do only have two suggestions.

    1. Use guid to avoid distributed key creation problem
    2. If you know you will only have a few hundred inserts when disconnected, get a batch of keys over a webservice when connected and store them temporarily on the client before use.
    Maybe that helps

    Cheers
    Oliver
    Tuesday, December 23, 2008 5:53 AM