This architecture also handles changes in network connectivity. If you lose or remove network connectivity during synchronization, when you regain connectivity, the Client and Server Agents pick up where they left off in the synchronization process. In addition, the Server Agent won't synchronize with the publisher until all changes have been sent from the subscriber.
The key to implementing merge replication is understanding how your application will use the data in SQL Server CE. The easiest way to handle asynchronous updates is to partition the publications so that each subscriber receives only the data for which it is responsible. Revisiting the sales representative example, each salesperson's Windows CE device would subscribe to a publication that holds the data that is specific to that person's customers. SQL Server CE also supports dynamic filters that let each client receive a subset of the publication's data, so that each salesperson sees only his or her data. Another feature of merge replication is that you can create a custom conflict resolver that applies your company's rules to the changes. For example, a sales manager's changes could override changes by all other salespeople, or exceeding a credit limit could invalidate an entire order.
An alternative to merge replication is RDA, in which the client initiates and controls the flow of data instead of depending on a publisher or distributor to coordinate updates. The most significant difference between merge replication and RDA is that RDA supports getting data from SQL Server 2000, 7.0, and 6.5, whereas merge replication supports only SQL Server 2000 publishers.
With RDA, the SQL Server CE Server Agent acts as the intermediary between SQL Server CE and a SQL Server 2000, 7.0, or 6.5 server. The client application running on Windows CE uses the RDA object, which is an ActiveX component, to pull the contents of a table down to the client and push changes back to the server. If you need to send SQL statements to the server, you can use RDA's SubmitSQL method.
Using an RDA object is relatively simple. The InternetURL property stores the address of the IIS server that has the SQL Server CE Server Agent. The Pull method takes the names of a table in a local database, a SELECT statement, and an OLE DB connection string as parameters, contacts the SQL Server CE Server Agent, which executes the query on the server specified in the connection string, and stores the result set in the local table, which the Pull method creates for you. If your program specifies that it wants to push changes back to the server, you can turn on tracking when you call the Pull method. Calling the Push method with the local table name sends the changes back to the original source table.
Whether you choose merge replication or RDA depends mainly on how your users will use data on the Windows CE device. Merge replication is well suited to environments in which multiple people through multiple applications can update tables. If the data on the server mostly supports a Windows CE application that operates independently of other users, RDA is probably the best choice. Merge replication requires that the server keep a change history; RDA manages changes on the client device. Merge replication lets SQL Server CE read and update multiple tables at the same time; RDA works on a single table at a time, so an application would need to call the Pull and Push methods for each table it uses.
Prime Performance
SQL Server CE runs on any platform that Windows CE 2.x supports, including the H/PC and PPC platforms, or that Windows CE 3.0 supports, including the Pocket PC platform. RDA and merge replication run on all Windows CE versions and work with IIS 4.0 running on Windows NT Server 4.0 with Service Pack 5 (SP5) and IIS 5.0 running on all versions of Windows 2000. All of these features run on embedded platforms as well.
eMbedded Visual Tools supports all CPUs on which Windows CE 2.x and 3.0 run, and interactive debugging works with serial port, IrDA, USB, and network connections. ADOCE 3.1 and ADOXCE 3.1 are new versions that specifically add support for SQL Server CE. ADOCE 3.0 will not work with SQL Server CE.
Microsoft's early benchmarks show that the alpha version of SQL Server CE is substantially faster than Windows CE's data provider, CEDB. On a Jornada 820, which is a handheld platform and has a StrongARM 1100 CPU running at 190MHz, SQL Server 2000 CE created four indexes in 24.244 seconds, whereas CEDB took 6261.32 secondsalmost 30 times longer. Loading 15K of data took 19.092 seconds for SQL Server CE and 170.28 seconds for CEDB. A seek update without an index took 17.804 seconds on SQL Server CE and 543.2 seconds for CEDB. Most tests showed CEDB taking anywhere from 10 to 30 times longer than SQL Server CE to perform the same task.
The new Compaq IPaq H3600, which should be available at press time, will feature a 206MHz processor in a palm-sized device. Although the Compaq processor is slower than most of today's desktops, it's fast enough to provide good response time for applications that run on Windows CE. Even my HP Jornada 545, which has a 131MHz CPU, offers reasonable response times. Given Microsoft's track record, the final release will likely beat the performance of the alpha release.
Get Ready
At the Windows DNA 2000 Readiness Conference in March, Microsoft showcased an example of a bread bakery in Mexico City. Each delivery person has a Windows CE device with an application that lets the delivery person take orders and note inventory when visiting client stores. When the salesperson returns to the bakery, the wireless network card connects to the network, and SQL Server CE replicates all the changes to the bakery's order and inventory databases. The orders flow into the production system database, which determines how many loaves of bread the bakery will bake the next day. At the same time, new delivery instructions download to the delivery person's device. The process occurs automatically as soon as the delivery person comes in range of the bakery's wireless network.
Such scenarios offer great promise for the future of mobile computing. Laptop computers have enabled many companies to make their databases more mobile, but even the smallest laptop is heavy and expensive compared with most Windows CE devices. In June, IBM announced that it increased the capacity of its tiny Type II Compact Flash form factor hard disk to 1GB. Because 32MB of RAM is the standard on the palm-sized platforms and 64MB of RAM is common on the handheld platform, the addition of a 1GB hard disk makes Windows CE devices viable database application platforms. And with the combination of eMbedded Visual Tools and SQL Server CE, developers can create database applications that run on smaller, lighter, more portable devices than laptops.