[ Team LiB ] |
Recipe 10.2 Maintain Multiple Synchronized Copies of the Same Database10.2.1 ProblemYou have a database that you'd like to distribute to mobile salespeople. Multiple users update the central copy of the database on a daily basis, and the salespeople also need to make updates to their own copies of the database. Is there any way to let everyone make updates and synchronize these copies when a salesperson returns to the office and plugs into the network? 10.2.2 SolutionAccess 95 introduced a powerful feature called replication, which allows you to keep multiple copies of the same database synchronized. Subsequent versions of Access have continued to improve on replication. In this solution, we discuss how to set up a database for replication, how to synchronize the replicas, and how to deal with synchronization conflicts.
10.2.2.1 Replicating a databaseThe steps for replicating a database using the Access menus are as follows:
Figure 10-10. The create replica progress dialog
Figure 10-11. The database container of the replicated 10-02 database
10.2.2.2 Synchronizing replicasReplicas in a replica set remain independent of each other until you choose to synchronize them. You can synchronize only replicas that are members of the same replica set; that is, only copies derived from the same design master. You synchronize replicas a pair at a time. When you are ready to synchronize a pair of replicas—for example, when a salesperson returns to the office and plugs his laptop into the office network—follow these steps:
Figure 10-12. The Synchronize Database dialog
10.2.2.3 Resolving conflictsIf multiple users have made updates to the same record in different replicas, one or more users will be informed of conflicts when they close and reopen the database to complete synchronization. See Recipe 10.2.3 of this solution for more details on how Access determines which change "wins" a synchronization conflict. If one or more of your edits "loses" in the exchange, you will see a dialog the next time you open the database, stating "This member of the replica set has conflicts from synchronizing changes with other members. Do you want to resolve conflicts now?" To resolve the conflicts, follow these steps:
Figure 10-13. The Microsoft Replication Conflict Viewer dialog
Figure 10-14. A conflict resolution form for tblCustomer
10.2.3 DiscussionTo summarize, when you replicate a database in Access, you change the database structure so that Access can track changes made to the database and later synchronize those changes with other copies of the database. Copies of a replicated database are called replicas; the original master copy is called the design master. You can make design changes only to the design master. The design master and its replicas make up a replica set. You can synchronize only members of a replica set. When converting a nonreplicated database to a replicated one, Access makes the following changes:
When you synchronize replicas, Access compares records in each replica using the hidden s_Generation field to determine if records have been updated. During synchronization, only changed rows are exchanged between replicas. When conflicting edits are detected during a synchronization exchange, Access determines which edited version of a record "wins" an exchange using the following rules:
Only users with "losing" edits are notified of conflicts. Replication works best when your replicas are only loosely coupled, and it isn't critical that all changes be synchronized as soon as they are made. It is best to replicate only tables, and not forms, reports, or other Access objects. Although Access supports replicating other database objects, it doesn't always work well. You may find that in attempting to synchronize design changes, only partial changes are propagated to the replicas, creating additional headaches. In addition, Access replication is suitable only when you anticipate a small or moderate number of updates to the same records in different replicas. If you need real-time synchronization or if you anticipate a high number of updates to the records across replicas (conflicts), you may wish to consider using the replication services built into server databases such as Microsoft SQL Server or some other system. |
[ Team LiB ] |