oday, more and more organizations are mobilizing their workforce. Workers are equipped with phones, PDAs, and notebook computers while they are on the road. Often, they need to access information stored on their corporate serversthings like product information, orders, and so on. One way to obtain this information would be to connect directly to the corporate servers through VPN connections or via web services. However, doing so requires them to stay connected, which is not always possible. A better approach is to build an Occasionally Connected System (OCS) where the data required is cached on the user's device. When the user has network connectivity, the data can then be synchronized with the backend database. This approach has many advantages, the main one being the elimination of the need to always stay connected and the ability to access important data locally.
With Visual Studio 2008, Microsoft has recently released the first version of Sync Services for ADO.NET, which enables the synchronization of databases between the different devices and computers. This article will walk you through the basics of Sync Services and how it works. You'll also learn how to use Visual Studio 2008 to build applications using Sync Services.
Synchronization Services Architecture
Figure 1 shows the Sync Services architecture and the various objects that make it possible.
|Figure 1. Sync Services Architecture: And the various objects that make it possible.|
- SyncTable: The SyncTable object represents the client tables involved in synchronization. For each table you are synchronizing, a SyncTable object is used.
- SyncAgent: The SyncAgent object orchestrates the entire synchronization process.
- SqlCeClientSyncProvider: The SqlCeClientSyncProvider object abstracts a SQL Compact database and shields SyncAgent from the implementations of the client database.
- DbServerSyncProvider: The DbServerSyncProvider object abstracts a database server and shields SyncAgent from the implementations of the server database.
- SyncAdapter: The SyncAdapter object represents a set of data commands that is used to retrieve and apply changes at the database server. For each table you are synchronizing, a SyncAdapter object is used.
- ServerSyncProviderProxy: The ServerSyncProviderProxy object is used in N-tiered scenarios. Instead of SyncAgent communicating directly with the DbServerSyncProvider object, the SyncAgent object uses the ServerSyncProviderProxy object to relay calls to the DbServerSyncProvider deployed on another server.
In a two-tier environment, all the above objects run on the same process or node. In an N-tier environment, the DbServerSyncProvider
objects are deployed on a separate server from the client.
Sync Services uses database triggers and additional columns in tables to track changes in each database. During synchronization, this information is is used to synchronize both client and server.