Wednesday, January 31, 2007

Three Sample C# SSCE Sync Services Projects

As mentioned in my January 28, 2007 post, "Microsoft Releases Synchronization Services CTP," Rafik Robeal has posted the source code for C# demo applications that synchronize data bidirectionally between SQL Server 2005 [Express] (SS[X], server) and SQL Server 2005 Compact Edition (SSCE, client). Rafik is the primary Microsoft participant in the new Microsoft Synchronization Services for ADO.NET forum and writes MSDN's The Synchronizer blog. To build and run the three projects, you must download and install the Microsoft Synchronization Services for ADO.NET v1.0 CTP release of January 22, 2007, which installs a post-Orcas release of SSCE v3.5 and the Microsoft.Synchronization....dlls on your test machine.

The projects use simple orders and order_details tables that are empty to start. You add random rows to the two tables with buttons on a two-tab Windows form, optionally execute random updates and deletions on the SSCE client, and finally synchronize the client-side changes with the SS[X] server). Each base table has a corresponding tombstone table to track deletions.

Here's a screen capture of the main SyncForm.cs window displaying the order_details table: When you click the Synchronize button, the following window reports the results:

Following are brief descriptions of the three sample projects, each of which uses the same UI:

  • Offline AppDemo—Builder (released 1/25/2007) demonstrates basic Sync Services functionality by using the SqlSyncAdapterBuilder to generate a bidirectional SyncAdapter for each table that includes information on the base and tombstone table columns. SyncAdapters are similar to ADO.NET 2.0 TableAdapters. There's more information in Rafik's Demo I: Offline Application—SyncAdapterBuilder post and my earlier post gives some tips to get started on the right track.
  • Offiline AppDemo-T-SQL + SProc (released 1/28/2007) substitutes T-SQL queries and stored procedures executed by SqlCommand objects for the SqlSyncAdapterBuilder. Using T-SQL and SProcs provides exposes SyncAdapter code for customizing the process and gives additional insight into how SyncAdapters work. Documentation is in the Demo II: Offline Application—TSQL+SProc post.
  • Offline AppDemo—WebServices (released 1/30/2007) illustrates the N-tier approach by moving the server-side code to a Web service and wrap the client-side code to enable it to plug into the Web service's sync agent. Using a Web service complicates the installation, so be sure to read Demo III: Offline Application—WebService before attempting to build and run the project.

These three demo apps provide the basic code that you need to test two-tier and N-tier synchronization with more complex data structures. Hopfully the Sync Services documentation will arrive as promised in early February 2007.

Update 2/5/2007: Rafik provides a comparison of Sync Services with SSCE as the subscriber (client) and SQL Server 2005 Merge Replication with SQL Server 2005 as the publisher and SQL Server or SQL Express as the subscriber (Synchronization Services for ADO.NET Vs SQL Merge Replication). It would be interesting to compare a scenario with SQL Server 2005 as the publisher and SSCE as the subscriber.

Update 2/7/2007: Rafik has added a fourth OfflineAppDemo for concurrency conflict detection and resolution. See a summary with screen captures here. Get further details and download the project here. Technorati tags: , , , , , , , , .