What’s new in Sync Services for ADO.NET 2.0?

As you know we’ve released the V1.0 of Sync Services for ADO.NET as a standalone package. It is also bundled with Visual Studio 2008 with additional Sync Designer experience. Sync Services is one component in a comprehensive sync platform offering from Microsoft called Microsoft Sync Framework that we unleashed recently. The Sync Framework is publicly available as an early CTP release. With it, you will find a new version of Sync Services for ADO.NET that adds on top of V1 components a new provider called DbPeerSyncProvider. Well, let’s talk a little bit about this new guy.

DbPeerSyncProvider Overview

Sync applications tend to evolve over time; let’s say you started by adding offline capabilities to your application, your customers loved it, but then they ask for more. They wanted to have the same experience on the device; well, no big deal, you tweaked your app to work on devices as well as desktop. Both flavors of your app take data offline and synchronize with some useful service you have on the cloud. Now, some savvy customers will come to you and say, “My data plan is expensive, can I synchronize my mobile device with the desktop instead of going to the web?” others might say, “we need to be able to synchronize with one another in an ad-hook fashion!” ... So now you have a growing demand to support a different model than that of a central server database. You need to build peer to peer sync system. Your central database will become yet another peer(s) in an ever growing topology!

This scenario is not uncommon, but technology seems to lack big time when you move to loosely-coupled multi master sync scenarios. This is where DbPeerSyncProvider comes in to fill this gap. 

DbPeerSyncProvider Architecture

You will feel at home when looking at the DbPeerSyncProvider interface. It follows the same programming model introduced with DbServerSyncProvider. Let’s see what commands we have on the provider and sync adapter:

Provider Commands

The provider interface contains thee commands that you need to define. These commands are used by the provider to manage key information about this node including metadata summary for the contents on this node. This summary is formally known as ‘knowledge’ object in the sync framework. Using the knowledge object, one can tell very quickly if two nodes are in sync or not. The provider commands are:

  • SelectScopeInfoCommand
  • UpdateScopeInfoCommand
  • SelectNewTimestampCommand

The ‘scope’ refers to the set of tables that this provider synchronizes. A given node could have multiple scopes. This is similar to the table group concept in the client\server provider terminology.

Adapter Commands

Each adapter represents a table in the scope on the node. The sync adapter interface carries nine commands that can be further categorized as follows:

 Peer Sync Adapter Commands

  1. Change Enumeration
    Just one command is used to enumerate incremental changes from the database. This is different from the DbServerSyncProvider where we have three commands instead.
  2. Change Application
    As you might expect, there are three commands for applying inserts, updates and deletes. In addition there is another command for getting a hold of a given row or its metadata. This command is mostly used during change application.
  3. Tombstone Cleanup
    The peer provider needs to record in its summary the fact that tombstones have been deleted. That said, the provider will use this command in which you, the developer, defines the criteria for deleted rows to be cleanup (tombstones older than 10 days, for example), to find those tombstones and record the needed metadata for you then delete the rows. No worries, this command is just a simple select statement, the provider will do the heavy lifting for you.
  4. Metadata Management
    In the p2p sync world, metadata is king! By this statement I am trying to underline the importance of the metadata management and the ability of the provider to tweak them as it sees fit. There are three metadata management commands that give the provider the control to insert, update and delete metadata for a given row.

This just a quick introduction to our new provider, there is a lot to talk about as we move forward with building sharing applications using this provider. Check out the documentation on the sync dev center, and give the bits a test drive!

More to come…

Update: Just to let you know, I left Microsoft to start a new company, Raveable Hotel Reviews. See examples: Top 10 Hotels in Myrtle Beach, Best Hotels in NYC,Romantic Hotels in Seattle, Kid Friendly Hotels in Orlando and Top 10 Hotels in San Diego. Your feedback is welcome on twitter.com/raveable, raveable blog.

I am not actively blogging about Sync Technologies. Please see Sync Team Blog for more updated content.



Comments (7)

  1. jgilkey says:

    Thank you! Been waiting for this for a while 🙂

  2. vRITHNER says:

    Hi Rafik,

    Just a question: I’m struggling to play with CTP1 bits; all samples included inside "C:Program FilesMicrosoft Sync Frameworkv1.0RuntimeADO.NETV2.0Samples] still use version 1.0 of Microsoft.Synchronization.Data.dll and a lot of code must be changed to make it work.

    I want to create a synchro layer for my application but I need a sample to start correctly.

    Do you have one good sample which use the new CTP1 bits ?




  3. MSDN Archive says:

    Hi Vince,

    The samples in this directory are the one you want to look into. These are the ones I wrote with my team. You should not need to change the code at all. I did install CTP1 on a clean machine and then compiled the sample which worked just fine. Try to uninstall exiting stuff first and I will look into this from my side.



  4. Check the post on whatz new on Sync Services 2.0 version here.

  5. udaiappa@hotmail.com says:

    How to we use DbPeerSyncProvider with SQL Server 2008 change tracking.  I would like to bind all the adapter column property into changetable columns.

  6. MSDN Archive says:

    Hi englewood,

    Using SQL Change tracking with Peer Provider is not as straight forward at this point. For one, you cannot edit SQL Change Tracking metadata thus you cannot really write Update or Delete metadata commands. That said, there are other ways to do this. The sync team should post some details on how to get this done.




    Dear All,

    SYNC IS VERY VERY SLOW (With batching) using bidirectional by terminal

    I have implemented batching from syncguru website, now it is working fine, but it takes a long time to complete the process. "Demo VIII: Offline Application – Batching"

    the link is http://www.syncguru.com/…/SyncServicesDemoBatching.aspx

    Total records in my table : 60,000 records

    BatchSize : 3000

    Total Duration : For updating 1000 records, it takes more than 90 seconds

    i need to reduce the "Total Duration" upto 30 seconds atleast.

    Please provide your valuable suggestions.

    Thanks in advance.





    —  ***********************************************  

    —     NewAnchor proc with batching support  

    —  ***********************************************  


    create procedure [dbo].[sp_new_batch_anchor] (  

           @sync_last_received_anchor bigint ,  

           @sync_batch_size int,  

     @sync_max_received_anchor bigint output,  

     @sync_new_received_anchor bigint output,    

     @sync_batch_count int output)    


    if @sync_batch_size <= 0  or @sync_batch_size is null  

    set @sync_batch_size = 3000  

    if @sync_max_received_anchor is null  

        set @sync_max_received_anchor =  min_active_rowversion()-1 — @@DBTS –min_active_rowversion()-1  

    — simplest form of batching  

    if @sync_last_received_anchor is null or @sync_last_received_anchor = 0  


        set @sync_new_received_anchor = @sync_batch_size  

     if @sync_batch_count <= 0 or @sync_batch_count is null  

      set @sync_batch_count = (@sync_max_received_anchor /  @sync_batch_size) + 1  




        set @sync_new_received_anchor = @sync_last_received_anchor + @sync_batch_size  

     if @sync_batch_count <= 0 or @sync_batch_count is null  

      set @sync_batch_count = (@sync_max_received_anchor /  @sync_batch_size) – (@sync_new_received_anchor /  @sync_batch_size) + 1  


       — check if this is the last batch      

       if @sync_new_received_anchor >= @sync_max_received_anchor  


           set @sync_new_received_anchor = @sync_max_received_anchor          

     if @sync_batch_count <= 0 or @sync_batch_count is null  

      set @sync_batch_count = 1  


Skip to main content