Programming Common Peer-to-Peer Synchronization Tasks
The following topics in this section provide background information, procedural content, and complete code examples for common peer-to-peer synchronization tasks that you can perform by using Sync Services for ADO.NET 2.0.
In This Section
How to: Use Session Variables for Peer-to-Peer Synchronization
How to: Handle Data Conflicts and Errors for Peer-to-Peer Synchronization
Example Applications in the How-to Topics
Each how-to topic contains a console application. This application is written in both C# and Visual Basic and demonstrates particular features of the API. Although it is quicker to show only code examples for a specific task or feature, it is much easier to understand how Sync Services works if you see a particular feature in a fairly complete context.
Each application contains the following classes, and also other classes that are relevant to the features that are being described:
Program
This class sets up synchronization and calls methods from theUtility
class. TheUtility
class handles all functionality that is not directly related to synchronization, such as holding connection string information and making changes to the server and client databases.SampleSyncAgent
This class is derived from SyncOrchestrator.SampleSyncProvider
This class includes aSetupSyncProvider
method that creates: a DbSyncProvider object for each node that is being synchronized; and a DbSyncAdapter object for each table that is being synchronized.
The code for all the applications has been tested on Visual Studio 2008, SQL Server 2005 Service Pack 2, and SQL Server 2008.
To run each application
Execute the "Custom Change Tracking for Collaborative Scenarios" Transact-SQL script in Setup Scripts for Sync Services How-to Topics. This script creates three databases, each with a set of tables and triggers, and a set of stored procedures. To delete and reinsert sample data, use the
usp_ResetPeerData
stored procedure.Copy the
Utility
class code from Utility Class for Sync Services How-to Topics. Paste this code into each application that you want to run, or create a DLL from the code and reference that DLL from each application.Add references to the following DLLs:
Microsoft.Synchronization.dll
Microsoft.Synchronization.Data.dll