Executive Summary

This chapter is a continuation of the discussion in the previous chapter covering the essential architectural concept of synchronization. Whereas in the previous chapter the focus was on synchronizing file-based and XML data, this chapter focuses on the two built-in synchronization mechanisms of SQL Server 2000 Windows CE Edition 2.0: RDA and merge replication. The obvious advantage to using these mechanisms is that the connectivity architecture and infrastructure work have already been done, thereby easing the work of architects and developers to integrate this functionality into custom solutions.

The connectivity architecture is the same for both RDA and replication and involves a client agent on the device making HTTP(S) requests to a server agent running on an IIS server. The server agent then connects to SQL Server and either executes commands, synchronizes replicated data, or returns rows to the client agent for processing. The client agent API is exposed through the SqlCeRemoteDataAccess and SqlCeReplication classes in the SqlServerCe .NET Data Provider so that Compact Framework applications can initiate requests. On the server side the configuration of IIS is managed by the SQL Server CE Connectivity Management MMC snap-in that administrators can use to configure the IIS virtual directory and its associated security. This architecture is attractive because of its accessibility via HTTP, security using IIS and SSL, performance through its use of a compression algorithm to transmit data, and reliability because the underlying block-based protocol includes automatic restarts at the last successful block.

RDA can be thought of as the more lightweight of the two mechanisms because it does not require any special configurations on the SQL Server. It can be used to pull rows on a per-table basis to the device, optionally track changes made on the device, and then later push those changes back to the server using a simple optimistic concurrency-based model. Error rows are then saved on the device for later review. For this reason, RDA is ideal for loading data that will be both dynamic and static, capturing data (where the data is created on the device such as through a bar code reader), and dealing with data that is highly partitioned, where it is unlikely that two users will update the same row. RDA can also be used in a connected mode to submit any SQL statement to the server (as long as it does not return rows). The API exposed by the SqlCeRemoteDataAccess class is fairly straightforward, but developers may wish to wrap some of its functionality, especially setting its connectivity and security properties, into a Singleton class.

Merge replication allows a SQLCE client to act as a subscriber to a merge publication created on SQL Server 2000. While this mechanism requires more server configuration and planning, it allows more control as well through server-based row and column filtering (including dynamic filters), the ability to load and synchronize multiple tables, server-based conflict detection and resolution, and bidirectional data flow, whereby changes made on the server also show up on the device. Together, these make replication ideal for occasionally connected applications with shared-data scenarios and where data must be incrementally updated on the device. The SqlCeReplication class exposes a simple set of methods for creating subscriptions and synchronizing data.