Replication

[Previous] [Next]

The Replication sample is designed to serve as an introduction to using the replication and synchronization features of Jet and Replication Objects (JRO), discussed in Appendix A. This sample creates three new Access 2000 databases in the sample code's directory: Master.mdb, Replica.mdb, and Partial.mdb. The first database acts as the master database in the replication topology. The second database represents a full replica, and the third represents a partial replica.

The first step is to create and populate the master database. The sample code uses ADOX to create a table that will participate in replication, and then uses ADO to insert three rows into the table before marking the database as replicable. You might not want all the tables in your database to participate in replication, so the sample also creates a table named Local, which it marks as nonreplicable.

The sample then uses the master database to create the new full and partial replica databases. Once that's done, the code connects to the partial replica database and sets up a filter to determine which data from the master database gets replicated to the partial replica.

To demonstrate JRO's synchronization features, the sample modifies two rows in both the master and the full replica, and then synchronizes both databases. Note that there's an overlap—one row (CustomerID = 3) is modified in both databases. This will cause a conflict when the databases are synchronized.

After synchronizing these two databases, the sample code checks for conflicts. If conflicts occurred, the code displays a dialog box asking whether you want to resolve the conflicts. Jet stores information about conflicts in special system tables. If you indicate that you want to resolve the conflicts programmatically, the code loops through these system tables and deletes their contents.

Although this doesn't realistically constitute resolving the conflicts, the Jet engine assumes that if you clear the contents of these tables, you've resolved the conflicts. If you tell the sample that you don't want to resolve the conflicts programmatically, the next time you open the databases in Access 2000, Access will display dialog boxes indicating that conflicts occurred.

As I explained in the "Questions That Should Be Asked More Frequently" section of Appendix A, resolving conflicts is not easy. Actually, I intentionally based the Replication sample on a scenario I felt was a common but unwise one. If at all possible, you should avoid using replication in scenarios where such conflicts occur.



Programming ADO
Programming MicrosoftВ® ADO.NET 2.0 Core Reference
ISBN: B002ECEFQM
EAN: N/A
Year: 2000
Pages: 131
Authors: David Sceppa

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net