January 22, 2021
Hot Topics:

Getting Started with Microsoft Synchronization Services for ADO.NET

  • By Rachel Baker
  • Send Email »
  • More Articles »

You now must define the Synchronize method used in the code above. All this method does is call the built-in synchronize method and then display the results to the user. I have used a message box for simplicity:

Listing 16: Synchronize code

public static void Synchronize()
   SampleSyncAgent syncAgent = new SampleSyncAgent();
   SyncStatistics syncStats = syncAgent.Synchronize();

   StringBuilder sb = new StringBuilder();
   sb.AppendLine("Download Changes Applied: " +
   sb.AppendLine("Download Changes Failed: " +
   sb.AppendLine("Total Changes Downloaded: " +
   sb.AppendLine("Total Changes Uploaded: " +
   sb.AppendLine("Upload Changes Applied: " +
   sb.AppendLine("Upload Changes Failed: " +

   MessageBox.Show(sb.ToString(), "Sync Results");

The SyncAgent's Synchronize method returns several useful statistics. Above, I just take those statistics and display them, but you could use them to determine the logical steps for your program to take after synchronization.

If you are anxious at this point (and I am sure you are), you could run your program and watch it create the client database; it will be located in the bin directory where your program is compiled. The final steps for finishing up this sample are to add user interface components so that your user can modify information for their customers. Mine looks like this, but obviously it could take many forms:

Click here for a larger image.

Figure 3: Sync example client form

Because in my example the server and client are on the same machine, my rudimentary form can allow the user to see what is on the server and what is in the client database. As you can see from the screenshot, this client only has two customers although there are several customers for multiple users in the server database. You can play around with the different tables and notice what changes get pushed back and forth between the databases. Remember, if you update a record directly in the server database, make sure you change the UpdateId to '00000000-0000-0000-0000-000000000000' to see the changes filter down to the clients.


Creating synchronization logic for an offline, occasionally connected application can be difficult and complex. Microsoft Synchronization Services for ADO.NET attempts to support this effort by using the lightweight SQL Server Compact Edition to cache data locally for a client. As I am sure you have seen, even when using a pre-existing sync framework, the logic and work necessary can be extensive. The steps outlined in this article will help you start becoming familiar with sync services and provide a foundation for laying out your sync scenario.

Download the Code

You can download the code that accompanies this article here.

About the Author

Rachel Baker (MCPD, MCTS) is a developer specializing in Windows-based solutions at Crowe Chizek in Oak Brook, Illinois. Reach her at rwireman@crowechizek.com.

Page 8 of 8

This article was originally published on December 17, 2007

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date