Chapter 24. Replication Made Easy

What Is Replication?

Access 95 was the first desktop database that included built-in replication capabilities. Replication has further matured with the introduction of Access 97; it's a powerful feature that's becoming increasingly important in today's world of mobile and distributed computing. This chapter teaches you about replication and how to implement it through both the user interface and code.

Uses of Replication

Data replication is the ability of a system to automatically make copies of its data and application objects in remote locations. Any changes to the original or to the copies are propagated to all other copies. Data replication allows users to make changes to data offline at remote locations. Changes to either the original or the remote data are synchronized with other instances of the database.

To see an example of data replication at work, say you have a team of salespeople who are out on the road all day. At the end of the day, each salesperson logs on to one of the company's Windows NT servers through DUN (Dial-Up Networking) or RAS (Remote Access Services). Each salesperson's transactions are sent to the server. If necessary, any changes to the server data are also sent to the salesperson. In addition to data being replicated, if the developers in the organization are busily adding forms, reports, and modules to the database's master copy, any changes to the application components are also updated in the remote copies as users log on to the system.

This example illustrates just one of the several valuable uses of replication. In a nutshell, data replication is used to improve the availability and integrity of data throughout an organization or enterprise. The practical uses of data replication are many; they can be categorized into five general areas, explained in the following sections.

Sharing Data Among Offices

In today's global economy, it's the norm for companies to have many offices distributed throughout the country, or even the world. Before Access 95, it was difficult to implement an Access application that would support sharing data among several offices. However, with replication, each office can have a replica of the database. Periodically throughout the day, each office can synchronize its changes with corporate headquarters. How often the synchronization happens depends on the frequency required for data at each location to be current at any given moment.

Sharing Data Among Dispersed Users

Sharing data among dispersed users is illustrated by the salesperson example used earlier. This implementation of replication generally involves mobile users who connect to the network after modifying data out on the road. Because only incremental changes are transferred from the Design Master (the original) to the replicas (the copies), and from the replicas to the Design Master, this form of replication makes the mobile computing scenario economically feasible.

Reducing Network Load

Replication can be very effective in reducing network traffic loads. The Design Master can be replicated onto one or more additional servers. Distributed users can then make changes onto one of the additional servers, which significantly improves performance by distributing the processing load throughout the network. Changes made to the data on the additional servers can be synchronized with the main server periodically during the day. How often synchronization occurs depends on the need for data to be current at any moment in time.

Distributing Application Updates

Replication is an excellent vehicle for distributing application updates. Design changes can be made only to the Design Master; therefore, as users throughout the organization log on to synchronize with the Design Master, any structural changes to the application are sent to the user. This is much more efficient and effective than giving every user an entirely new copy of the application database each time a minor change is made to the application's schema.

Backing Up the Data in Your Application

Many people don't think of replication as a means of backing up application data, but replication is extremely well-suited for this task. Ordinarily, to back up an Access database, everyone must log off the system, but that's not necessary with replication. The synchronization process can occur periodically during the day while users are still logged on to the system, and all changes are replicated. Not only is this more efficient than backing up the entire database, but it also ensures that you can quickly be up and running on a backup server if there's a problem on a server.

Understanding When Replication Isn't Appropriate

Despite the many positive aspects of replication, replication is not appropriate in a couple of situations, such as when data consistency is critical. If an application requires that data be current at every given moment, then it isn't a good candidate for replication. Replication is also not effective when a large volume of existing records are modified throughout the day by many different users. In a situation like this, resolving conflicts that happen when multiple users update the same record wouldn't be practical.

An Overview of the Implementation of Replication

The following steps compose the replication process:

  1. Making a database replicable.

  2. Creating and distributing replicas.

  3. Synchronizing replicas with the Design Master.

  4. Resolving conflicts.

These steps can be done in the following ways:

  1. Through the Access user interface

  2. By using the Windows 95 Briefcase

  3. By using the Replication Manager

  4. By using DAO code

The steps needed for the replication process, and the alternatives for performing each step, are covered in this chapter. An overview of each alternative is outlined in the following sections.

The Access User Interface

The Access user interface gives you a series of menu items that allow you to perform all the steps of the replication process. The Tools | Replication menu has the following options: Create Replica, Synchronize Now, Resolve Conflict, and Recover Design Master. These menu options are covered throughout this chapter.

Briefcase Replication

The Windows 95 Briefcase supplies the foundation Access needs for the replication process. Users can simply drag a database file to the Briefcase to replicate it, make changes to the file while on the road, and synchronize the replica with the Design Master when they reconnect to the network. This is done because when Access 97 is installed, it registers a special class ID with the Windows 95 Briefcase. When a database is dragged to the Briefcase, the Briefcase's Reconciler code is called. When the user selects Update Selection or Update All from the Briefcase menu, the Merge Reconciler is called. Briefcase replication is available as an installation option through Windows 95, its successors, and Windows NT 4.0.

The Replication Manager

The Replication Manager is a sophisticated tool that's part of the Office Developer Edition. It's a mandatory player in the replication process when you're managing many replicas. Besides providing basic replication functionality, the Replication Manager lets you schedule the synchronization of replicas. In fact, the Replication Manager allows you to manage and intricately control all aspects of the replication process. The Replication Manager is covered in more detail in the section “Using the Replication Manager.”

DAO Code

Most aspects of the replication process can also be done by using DAO code, which can be used to make a database replicable, create and synchronize replicas, and get and set properties of a replicable database. DAO can easily be integrated with the other methods of replication. Although requiring the most time and effort on your part, DAO code lets you base replication on events rather than time and give your users a custom user interface for the replication process.

Programs That Support Replication Using DAO

Visual Basic 4.0, Excel for Windows 95, Excel 97, and Visual C++ all support replication using data access objects. You can't perform replication with these products by using either the Briefcase or the Office Developer Edition, however, so it's easier to manage the replication process on a machine that has Access installed.

The Replication Architecture: What Makes Replication Tick?

Now that you know what replication is and what alternatives you have for implementing it, you're ready to learn about what makes it happen. Six components are responsible for the replication process:

  • Tracking Layer

  • Microsoft Replication Manager

  • Synchronizer

  • File System Transport

  • Briefcase Reconciler

  • Registry Entries

The Tracking Layer

The Tracking Layer refers to the part of the Jet Engine that's capable of tracking and recording all the changes made to the Design Master and to each of the replicas. It's responsible for making sure changes are available to be transmitted to other replicas.

The Microsoft Replication Manager

The Replication Manager gives you the tools needed to support the replication process. It can also be used to generate reports on synchronization activity.

The Synchronizer

If you use the Briefcase or the Access user interface to manage the replication process, Jet handles the exchange of information between the replicas. If you use the Replication Manager to manage the replication process, the Synchronizer is responsible for monitoring the changes and handling the exchange of data between replicas.

When you're using the Replication Manager, each replica is assigned a synchronizer. The Synchronizer performs either direct or indirect synchronization between the members of a replica set. When synchronization is initiated, the Synchronizer tries to make a direct connection with the target member of the replica set. If both members of the replica set can be opened simultaneously by the Synchronizer, direct synchronization occurs, which means that changes from one member of the replica set are applied directly to the other member.

If the Synchronizer determines that the target replica set member isn't available, then indirect synchronization takes place. There are many reasons why the target replica set member might be unavailable; some possible reasons why a direct connection can't be established include the following:

  • The network server where the replica resides is down.

  • The computer containing the other replica is logged off the network.

  • The other member is currently involved in another synchronization.

  • The other member is not in a shared folder.

Regardless of the cause of an indirect synchronization, the Synchronizer for the first member of the replica set leaves a message for the Synchronizer assigned to the member of the unavailable replica set. This message is stored in a shared folder on the network that acts as a drop-box location for the target member. All messages sent while a member of the replica set is unavailable are stored in the drop-box location.

Note

If you need to determine whether a direct or indirect synchronization occurred, you can browse the MSysExchangeLog system table.

The Synchronizer is configured through the Replication Manager user interface and is covered in more detail in the section “Using the Replication Manager.”

File System Transport

The File System Transport is responsible for supplying messaging services to the Synchronizer.

The Briefcase Reconciler

The Briefcase Reconciler is another integral component of the replication architecture. As mentioned, it makes sure that a database is replicable and manages the merging of changes between the Briefcase replica and the Desktop replica.

Registry Entries

Several Windows Registry entries are responsible for helping with the replication process; a couple are shown in Figure 24.1. Notice the Replication Manager and Transporter subkeys under the HKEY_LOCAL_MACHINESOFTWAREMicrosoftJet3.5 key. These entries contain important path information used by the Replication Manager and the Synchronizer. The Briefcase Reconciler uses entries under HKEY_CLASSES_ROOTCLSID. Note that although the name has changed to Synchronizer, the key in the registry remains Transporter.

Replication and the Windows Registry.

Figure 24.1. Replication and the Windows Registry.

Understanding Replication Topologies

The topology for data synchronization determines which replicas synchronize with each other. The topology is essentially a blueprint for how the changes are merged between the members of the replica set. Different topologies are used for different situations, and the topology you choose is determined by your business needs and your organization's design. The synchronization topologies are Star, Ring, Fully Connected, Linear, and Hybrid. (See Figure 24.2.)

Examples of replication topologies.

Figure 24.2. Examples of replication topologies.

Star Topology

With the Star topology, a single hub periodically synchronizes with the rest of the replicas. The biggest advantage of this topology is simplicity and ease of programming. Another is that data doesn't have to travel very far. Each replica synchronizes with only one other database, the hub. However, this isn't particularly reliable. If the controlling replica is damaged or unavailable, the synchronization process can't take place. Another disadvantage of the Star topology is that the first replica to synchronize with the hub gets no data from the other replicas, but the last replica to synchronize with the hub receives all the data from the others. Issuing two rounds of synchronization can circumvent this problem. Finally, the Star topology can't be used with a large number of replicas because the entire load is placed on the hub.

Note

The Design Master must never be a hub. If you designate it as the hub, it's possible for partial design changes to be accidentally synchronized to the rest of the replicas. Instead, place the Design Master on one of the satellite machines and synchronize design changes with the controlling replica whenever they're complete and fully tested.

Ring Topology

With the Ring topology, each computer synchronizes with the next computer in the replication chain. There's no central point of synchronization in this scenario. The major advantage of the Ring topology is that the load is distributed throughout the satellite machines. The primary disadvantage is that it might take a long time for changes to be distributed throughout the replicas because there's no central point of synchronization. Furthermore, if one of the replicas in the chain is damaged or unavailable, the replication process stops, but this can be handled by using code that senses the problem and bypasses the unavailable machine.

Fully Connected Topology

When the Fully Connected topology is used, every replica synchronizes with every other replica. This topology offers several advantages. Its strongest point is that it makes sure data is the most current at any given moment because data is sent directly from each replica to all the other replicas in the replica set. For this reason, it's the best solution when the data must be as current as possible. Another benefit of the Fully Connected topology is its high level of redundancy. Also, because of the low level of latency (which means that at any given moment, it's likely the data isn't current) in the Fully Connected topology, the effect of any one of the replicas failing is minimal. The Fully Connected topology does have disadvantages, however. It requires the most overhead of any of the topologies because of the network traffic generated as each replica in the set synchronizes with all the others. Furthermore, the replication schedules must be staggered; otherwise, collisions will probably happen as more than one replica tries to synchronize with the same replica.

Linear Topology

The Linear topology is similar to the Ring topology except that the chain is never completed. For this reason, the Linear topology has the highest level of latency. The biggest advantage of the Linear topology is the low level of network traffic generated; however, this topology isn't practical for most applications because it takes more time for changes to reach all the replicas in the set.

Hybrid Topology

A Hybrid topology is any combination of the other topologies. In a complex application, it's usually not appropriate to use a single topology by itself. By combining the topologies, you can get exactly the results you need. Figure 24.2 illustrates just one example of a Hybrid topology—a Ring connected with a Star. You should experiment with the different configurations to see which topology best balances processing load, network traffic, and data latency.

Changes That Replication Makes to Your Database

Replication makes several changes to the database, but they're necessary to manage the demands of the replication process. The following changes are made to a database when it's replicated:

  • Fields are added to each replicated table.

  • Several system tables are added to the database.

  • Properties are added to the database document objects.

  • Sequential AutoNumber fields are changed to random AutoNumber fields.

  • The size of the database increases.

Fields Added to Each Replicated Table

During the replication process, the Jet Engine determines whether each table has a field with an AutoNumber data type and a ReplicationID field size. If it doesn't find a field meeting these criteria, it adds a field called s_Guid to the table that uniquely identifies each record. It's identical across replicas.

The Jet Engine also adds two additional fields to each table in the database: s_Lineage and s_Generation. The s_Lineage field stores the IDs of replicas that have updated a record and the last version created by those replicas; the s_Generation field stores information about groups of changes. These fields are visible only if you opt to view system objects (use Tools | Options).

System Tables Added to the Database

The Jet Engine also adds several tables to your database that track conflicts, errors, and exchanges made between the replica databases. MSysSidetable, MSysErrors, MSysSchemaProb, and MSysExchangeLog are the most useful of these tables; they can be viewed if you have chosen to view system objects.

MSysSidetable tracks tables that have experienced a conflict during the synchronization process. It stores the name of the side table that has the conflicting records.

MSysErrors tracks all unresolved synchronization errors. It's empty when all errors have been resolved. This table can be found in all the replicas.

MSysSchemaProb identifies errors that happened while synchronizing a replica's design. It's visible only if a design conflict has occurred between the user's replica and another replica in the set.

MSysExchangeLog is a local table that stores information about synchronizations that have taken place between the local replica and other members of the replica set.

Properties Added to the Database Objects

Several new properties are added to a replicable database. The database's Replicable property is set to True, and this property cannot be modified after it's set to True. The ReplicaID property is a unique ID assigned to each replica. The DesignMasterID property can transfer the Design Master status to another database, which is generally done only if the original master becomes irreparably damaged.

In addition to the properties that apply to the database, two properties can be applied to the tables, queries, forms, reports, macros, and modules in the database: the KeepLocal and Replicable properties. The KeepLocal property, applied to an object before the database is replicated, prevents the object from being copied to the other replicas in the set. The Replicable property, used after a database is replicated, indicates that the object will be replicated.

Changes to Sequential AutoNumber Fields

Another important change made to your tables when replicating a database is that all the AutoNumber fields are changed from incremental to random. Existing records aren't affected, but new keys are generated randomly because that reduces conflicts when the databases are synchronized. If all the copies generate sequential keys, you can see that conflicts will happen when you try to merge changes. By randomly generating primary keys, this conflict is much less likely to take place.

Changes to the Size of the Database

When a database is replicated, its size increases because of the added fields and tables. Generally, this increase isn't a problem. If disk space is at a premium, you should consider this aspect of replication before you decide to build replication into your application.

Making a Database Replicable

A replicable database is simply a database whose Replicable property has been set to True. If a database hasn't been marked as replicable, you can't replicate it. However, when a database has been flagged as replicable, the Jet Engine makes several changes to it to render it replicable. Until these changes are made, the database isn't recognized as part of a replication set and can't be synchronized with other databases.

When you're ready to replicate a database, you should take the following steps:

  1. Flag any objects in the database that you don't want replicated as local by setting their KeepLocal property to True.

  2. Make a replication Design Master by setting the database's Replicable property to True.

  3. Make copies—called replicas—of the Design Master.

You can make a database replicable by using the Access user interface, using the Windows 95 Briefcase, using the Replication Manager, or writing code. The following two sections cover using the Access user interface and the Windows 95 Briefcase. Making a database replicable by using the Replication Manager is covered in the section “Using the Replication Manager”; using code is covered in the section “Implementing Replication by Using Code.”

Rendering a Database Replicable with the Access User Interface

Choose Tools | Replication | Create Replica. Microsoft Access gives you a warning that it must close the database before proceeding. (See Figure 24.3.)

This dialog box warns you that Access must close the database before converting it to a Design Master.

Figure 24.3. This dialog box warns you that Access must close the database before converting it to a Design Master.

After selecting Yes, you see another dialog box asking whether you want Access to make a backup of the original database before continuing. (See Figure 24.4.) It's always a good idea to back up a database before replicating it because a database can't be returned to its nonreplicable state after it's flagged as replicable.

This dialog box prompts you to have Access create a backup of the database before it's replicated.

Figure 24.4. This dialog box prompts you to have Access create a backup of the database before it's replicated.

Next, you're prompted for the name and location of your new replica in the Location of New Replica dialog box. (See Figure 24.5.) After you click OK, the new replica is created and the process is finished.

The Location of New Replica dialog box allows you to specify a location and name for the replica.

Figure 24.5. The Location of New Replica dialog box allows you to specify a location and name for the replica.

Your original database is converted to a Design Master, and the replica is assigned the name and location specified in the Location of New Replica dialog box. If the replication process is completed successfully, the dialog box shown in Figure 24.6 appears. Notice that only the Design Master can accept changes to the database structure (schema).

This dialog box appears after successful replication of a database.

Figure 24.6. This dialog box appears after successful replication of a database.

Rendering a Database Replicable with the Windows 95 Briefcase

Instead of using the Access user interface to replicate a database, you can use the Windows 95 Briefcase. All you need to do is drag and drop the database file from Windows Explorer to the Briefcase icon on your desktop; then you see the dialog box shown in Figure 24.7.

This dialog box appears after you drag and drop a database to the Briefcase to be replicated.

Figure 24.7. This dialog box appears after you drag and drop a database to the Briefcase to be replicated.

Except for the final message you get, you see the same series of messages as you do when you choose Replication from the Tools menu in the Access user interface. Only one database can be used to make design changes, such as modifying table structures. The Briefcase dialog box, shown in Figure 24.8, asks which database you want to keep as the Design Master. Generally, you select the Original Copy rather than the Briefcase Copy. You do this because the briefcase copy is generally used only as a means to add, edit, and delete data when on the road.

The final dialog box you see during Briefcase replication offers you the choice of which copy you want to use for the Design Master.

Figure 24.8. The final dialog box you see during Briefcase replication offers you the choice of which copy you want to use for the Design Master.

Preventing Objects from Being Replicated

You might want to prevent specific objects in a replicable database from being replicated if, for example, certain data in your database is confidential or it's unnecessary for most users to see certain data. An employee salary table, for example, might be maintained and used in the master but isn't necessary for any of the replicas. The fewer objects that are replicated, the more effective the synchronization process is.

Designating that an object won't be replicated can't be done by using the Access user interface; it can be done only by using VBA code or the Replication Manager. To do this, set the KeepLocal property of the specific objects to True. When you try to set the KeepLocal property to True with VBA code, you get an error unless you have already appended the property onto the object. You must, therefore, include error handling in your code to handle this problem. Using the Replication Manager to flag an object as nonreplicable is covered in the section “Replicating a Database with the Replication Manager.” The code required to add the KeepLocal property to an object and set its value to True is covered in the section “Implementing Replication by Using Code.”

Creating Additional Replicas

After you have made one replica, you'll probably want to make more. These additional replicas are copies that can be distributed throughout the organization. They can be created by using the Access user interface, the Windows 95 Briefcase, the Replication Manager, or VBA code.

A sales organization, for example, might use multiple replicas for sales reps who take copies of the database along on their notebook computers. Each of these copies must be a replica created by the replication process rather than a copy made by the operating system. Otherwise, the work of each salesperson can't be synchronized with that of the others.

Replicas can be made with any of the four methods mentioned, but additional replicas can also be made from any member of a replica set. Each replica set is independent from all other replica sets. Replicas from different sets can't be synchronized with one another.

Creating Additional Replicas with the Access User Interface

To create additional replicas with the Access user interface, follow these steps:

  1. Open the database you want to replicate. You can open either the Design Master or any replica.

  2. Choose Tools | Replication | Create Replica.

  3. When prompted, supply a name for the new replica.

Creating Additional Replicas with the Windows 95 Briefcase

You can also make more replicas by dragging and dropping the Design Master—or any one of the replicas—to the Briefcase. If you drag and drop the Design Master to the Briefcase, you're prompted with a dialog box asking whether you want the Design Master or the replica to be placed in the Briefcase.

Synchronizing Replicas

To synchronize replicas means to reconcile all the changes between them. Modified records are changed in all the copies, deleted records are removed from all the replicas, and added records are appended to all the replicas.

The ability to synchronize is what makes data replication useful. Additions, modifications, and deletions are propagated among all the replicas in a set, which lets users see the changes other users made.

As with creating a replica, Access gives you four methods of synchronizing replicas: the Access user interface, the Windows 95 Briefcase, the Replication Manager, or VBA code.

Synchronizing Databases with the Access User Interface

To perform synchronization with the Access user interface, follow these steps:

  1. Choose Tools | Replication | Synchronize Now.

  2. The Synchronize Database dialog box opens. (See Figure 24.9.) Select the database you want to synchronize with and click OK.

    The Synchronize Database dialog box lets you select the database you want to synchronize with.

    Figure 24.9. The Synchronize Database dialog box lets you select the database you want to synchronize with.

  3. If no problems occur during the synchronization process, the dialog box shown in Figure 24.10 appears. You're warned that changes won't be visible until you close and reopen the database. If you select Yes, Access closes and reopens the database for you.

    This dialog box appears after a successful synchronization process.

    Figure 24.10. This dialog box appears after a successful synchronization process.

Synchronizing Databases with the Windows 95 Briefcase

The second way to synchronize replicas is by using the Windows 95 Briefcase. Simply open the Briefcase window and select the database file. On the Briefcase menu, click Update Selection. If you want to synchronize all the replicas in the Briefcase, click Update All to open the Update Briefcase dialog box. (See Figure 24.11.) Click Update, and the synchronization process is finished.

The Update Briefcase dialog box appears when you're synchronizing from the Briefcase.

Figure 24.11. The Update Briefcase dialog box appears when you're synchronizing from the Briefcase.

Resolving Replication Conflicts

When the Jet Engine tries to synchronize two databases, it might find that the same row has been changed in both databases, so a conflict results that must be handled. The rule is that the database in which the row has changed most often wins. If both rows have changed the same number of times, the winner is chosen randomly. This might sound frightening, but it isn't as bad is it seems because you can let the user know which changes were rejected.

You must know whether two members of the replica set contain conflicting information. Two users out in the field might have entered different information about a sale or a customer, so it's important that the program identify these inconsistencies and have a method for handling them.

If there are conflicts, you're warned about them when you try to open the database that has the conflicts. (See Figure 24.12.) Here, you're given the choice of whether to resolve the conflicts or not.

This dialog box warns of synchronization conflicts.

Figure 24.12. This dialog box warns of synchronization conflicts.

If the user selects Yes, the Jet Engine tries to identify the conflicts. After identifying the conflicts, the Resolve Replication Conflicts dialog box, shown in Figure 24.13, appears. Notice that in this example, the Jet Engine identified two conflicts in the tblClients table. The user can either resolve the conflicts or postpone the conflict resolution.

Use the Resolve Replication Conflicts dialog box to resolve conflicts between tables.

Figure 24.13. Use the Resolve Replication Conflicts dialog box to resolve conflicts between tables.

If the user clicks Resolve Conflict, another Resolve Replication Conflicts dialog box opens. (See Figure 24.14.) This dialog box shows the user each record that has a conflict, providing the opportunity to keep the existing record or overwrite with the conflict record.

In this Resolve Replication Conflicts dialog box, you view and resolve specific conflicts.

Figure 24.14. In this Resolve Replication Conflicts dialog box, you view and resolve specific conflicts.

After you select Overwrite with Conflict Record, yet another Resolve Replication Conflicts dialog box opens. (See Figure 24.15.) This dialog box warns the user that data in the conflict record will overwrite data in the existing record. The user can proceed with or cancel the process. If the user selects Keep Existing Record, the warning dialog box shown in Figure 24.16 appears; it warns the user that the existing record will be maintained and the conflict record will be permanently deleted.

This warning message appears when the user selects Overwrite with Conflict Record.

Figure 24.15. This warning message appears when the user selects Overwrite with Conflict Record.

This warning message appears when the user selects Keep Existing Record.

Figure 24.16. This warning message appears when the user selects Keep Existing Record.

After the user resolves all conflicts, a message appears indicating that he or she successfully resolved all conflicts.

Note

If you don't want to give your users this level of control over conflict resolution, you can write code to resolve conflicts in any way you want. This is covered in the section “Synchronizing a Database Using Code.”

Using the Replication Manager

The Replication Manager is a powerful tool that lets you take full advantage of replication in Access 97. It's included only with the Microsoft Office 97 ODE. The Replication Manager's major benefits include the following:

  • Lets you easily replicate a database

  • Allows you to easily create additional replicas

  • Gives you the ability to synchronize any replicas in the set

  • Allows you to schedule automated synchronization

  • Gives you the opportunity to view an object's replication history

  • Lets you easily manage replication properties

  • Offers a way to manage synchronization with replicas at remote sites

  • Allows you to perform synchronization over a LAN, an intranet, or the Internet

Running the Replication Manager for the First Time

The Replication Manager can be opened by using a Desktop shortcut or through the Windows 95 Start menu. The first time you run the Replication Manager, the Configure Microsoft Replication Manager Wizard appears. (See Figure 24.17.)

The Configure Microsoft Replication Manager Wizard.

Figure 24.17. The Configure Microsoft Replication Manager Wizard.

  1. Click Next to start the configuration process and launch the Configure Microsoft Replication Manager Wizard.

  2. This step of the Configure Microsoft Replication Manager Wizard asks whether you want to support indirect synchronization (See Figure 24.18.) With indirect synchronization, a Synchronizer for each of two replicas opens its own replica locally. A desktop computer leaves changes in a dropbox on the network. When the laptop connects to the network, the Synchronizer on the laptop finds the changes in its dropbox folder and applies them to the replica. The notebook leaves its changes in a dropbox folder of the desktop Synchronizer, which finds the changes and applies them. This is the preferred synchronization method for remote users who aren't always logged on to the network. Make your selection and click Next.

    Selecting a form of synchronization.

    Figure 24.18. Selecting a form of synchronization.

  3. If you choose to support indirect synchronization, the next step of the wizard gives you some information about Synchronization types. After reading this, click Next, and the wizard prompts you for a location for the dropbox folder. (See Figure 24.19.) Select a folder and click Next.

    Selecting a location for the Synchronizer to store changes.

    Figure 24.19. Selecting a location for the Synchronizer to store changes.

  4. You're then asked whether the computer on which you're running the wizard is an Internet server. Make your selection and click Next.

  5. If you indicate that the computer is an Internet server, the next step asks whether you want to use the Internet server to synchronize replicated databases. If you respond Yes and click Next, you're prompted for the name of the Internet server. Enter the name and click Next. (See Figure 24.20.) The next step asks you to provide a Shared folder and Share name used when synchronizing over the Internet. Click Next and you're prompted for an FTP alias name. Select the FTP alias name and click Next.

    If your computer is an Internet server, here's the place to tell the wizard its partial URL.

    Figure 24.20. If your computer is an Internet server, here's the place to tell the wizard its partial URL.

  6. Select a location for the log file used to record significant events that happen during the synchronization process. (See Figure 24.21.) Click Next.

    Selecting the name and location for the log file.

    Figure 24.21. Selecting the name and location for the log file.

  7. The next step of the wizard prompts you for a Synchronizer name. This name is used for an icon and as a descriptive name for the Synchronizer. This step of the wizard also asks whether you want to automatically start the Synchronizer when Windows starts. (See Figure 24.22.) The Synchronizer must be running for scheduled synchronization to take place, so you might want to select this option. Enter a Synchronizer name and indicate whether you want the Synchronizer to automatically start, then click Next.

    Selecting a name for the Synchronizer.

    Figure 24.22. Selecting a name for the Synchronizer.

  8. Click Finish to complete the process.

After the Configure Microsoft Replication Manager Wizard is finished, you can either convert a database to a Design Master or create a new replica. (See Figure 24.23.) You can perform these tasks any time, so you should click Close.

The Replication Manager launches for the first time.

Figure 24.23. The Replication Manager launches for the first time.

Note

If you opted to load the Synchronizer whenever you launch Windows, and you decide that you don't want the Synchronizer to be launched automatically, you must remove the Synchronizer icon from the Windows Startup folder.

Replicating a Database with the Replication Manager

In addition to using the Access user interface and the Briefcase to make a database replicable, you can also use the Replication Manager. It offers additional options, such as designating an object as local. Here are the steps:

  1. From the Replication Manager, click the Convert Database to the Design Master toolbar button or choose File | Convert Database to Design Master. The Convert Database to Design Master Wizard appears. (See Figure 24.24.)

    Launching the Convert Database to Design Master Wizard.

    Figure 24.24. Launching the Convert Database to Design Master Wizard.

  2. Select a file to convert and click Open.

  3. Indicate whether you want to make a backup of the database before converting it to a Design Master, then click Next. It's always a good idea to keep a backup of the unreplicated database.

  4. Enter a description for the new replica set and click Next. All replicas made from this Design Master will be members of the replica set you're creating. (See Figure 24.25.)

    Entering a description for the replica set.

    Figure 24.25. Entering a description for the replica set.

  5. You're then asked whether you want to make all objects available to the replica set or flag some of them as local. (See Figure 24.26.) If you click “Make some objects available to the entire replica set,” the Select Replicated Objects dialog box opens so you can designate selected objects as local. (See Figure 24.27.) To flag an object as local, clear its check box. Click OK when you're done.

    Designating whether you want all or just some objects to be replicated.

    Figure 24.26. Designating whether you want all or just some objects to be replicated.

    Flagging objects as local or replicated.

    Figure 24.27. Flagging objects as local or replicated.

  6. Next, indicate whether you want the replicas to be read-only. (See Figure 24.28.) The Design Master is the only place where you can make schema changes. If you want to limit data changes to the Design Master as well, select the option that makes all replicas read-only. In general, you should keep the default option of “I want to be able to create read-write replicas.” Click Next after you make a selection.

    Indicating whether the database will allow read-write replicas to be created.

    Figure 24.28. Indicating whether the database will allow read-write replicas to be created.

  7. The next step of the wizard asks whether you want to manage synchronization of the Design Master with the Synchronizer found on the current machine. If you answer No, synchronization must originate by another managed member of the replica set. Make your selection and click Next.

  8. Click Finish to complete the wizard; you're then notified of success or warned about any problems that happened during the conversion process.

Note

A table can't be designated as local if it's involved in a relationship with a replicated table.

Note

When you have more than one replica set, you must use the Managed Replicas tool on the Replication Manager toolbar to view a different replica set. Only one replica set can be viewed at a time.

Creating Replicas with the Replication Manager

Just as you can create replicas by using the Access user interface and the Windows 95 Briefcase, you can also create replicas with the Replication Manager. To do so, follow these steps:

  1. Click New Replica on the toolbar, then click Next.

  2. Select a Source and Destination for the replica. The Source is the name of the database you're replicating, and the Destination is the name of the replica. Click Next.

  3. Indicate whether you want to be able to make data changes within the replica. Click Next.

  4. Indicate whether you want the replica to be managed by the Synchronizer on the current machine. Click Next.

  5. Click Finish.

Note

If you create a replica of a database managed by a different Synchronizer, you must use the Replication Manager on the other computer to configure the Synchronizer.

Partial Replication

Jet 3.5 and Access 97 have introduced partial replication, meaning that only a subset of the data is replicated. This is useful when you have, for example, several sales people and you want each salesperson to have just his or her own data. However, you want all the salespeople to be able to synchronize their changes with other databases on the network. Partial replicas can be created by using the Partial Replica Wizard (you can download it from the Microsoft Internet site) or by using VBA code. The procedure for using VBA code to create a partial replica is in the section “Creating a Partial Replica Using Code.”

Synchronizing Replicas with the Replication Manager

Just as you can synchronize replicas with the Access user interface and the Windows 95 Briefcase, you can also use the Replication Manager by following these steps:

  1. From the Replication Manager, click the Synchronize Now tool on the toolbar.

  2. The Synchronize Now dialog box opens. (See Figure 24.29.) Here, you can designate details of the synchronization process. When you're done, click OK to finish the synchronization process.

    The Synchronize Now dialog box allows you to designate details of the synchronization process.

    Figure 24.29. The Synchronize Now dialog box allows you to designate details of the synchronization process.

Remote Synchronizations

You might be surprised that the Replication Manager map shows only one machine, even though you have many replicas. One icon appears for each Synchronizer involved in the replica set. Figure 24.30 shows two Synchronizers involved in the replication process: TECRA and DELL. The second site was set up by installing the Replication Manager on the second machine. Any replica from the local site can then be moved to the remote site by establishing a connection to the remote site and choosing File | Move Replica. You can locate the Managed Folder at the remote site and move the replica to the remote site's Managed Folder.

The Replication Manager map with two Synchronizers.

Figure 24.30. The Replication Manager map with two Synchronizers.

After both sites appear on the replication map, you can manage synchronizations by using the join line that connects them. You can right-click on the join line and select Synchronize Now or, to establish a schedule for synchronization, select Edit Schedule. Scheduling synchronization is covered in the next section.

Scheduled Synchronizations

Synchronizations can be scheduled between replicas managed by the same Synchronizer, or between replicas managed by two different Synchronizers. To schedule synchronization between replicas managed by the same Synchronizer, right-click on the icon representing the local Synchronizer and select Edit Locally Managed Replica Schedule. (See Figure 24.31.) From here, you can select the days and times when the replicas synchronize.

Use the Edit Locally Managed Replica Schedule dialog box to select the days and times when the replicas synchronize.

Figure 24.31. Use the Edit Locally Managed Replica Schedule dialog box to select the days and times when the replicas synchronize.

To schedule the synchronization process between two different Synchronizers, right-click on the join line and select Edit Schedule to open the Edit Schedule dialog box. Here you can schedule the specifics of the synchronization process between the two sites. The shading of each box indicates which Synchronizer initiates that exchange. If the connection can't be made when the exchange is initiated, the dropbox folder keeps a temporary log of the changes. Every 15 minutes, it retries the connection until it's successful.

Reviewing the Synchronization History

The synchronization history can be very useful. Besides giving you an audit trail, it helps you analyze the effectiveness of the topology and synchronization schedule you have selected. Three types of logs are kept by the Replication Manager:

  • The local synchronization history

  • The remote synchronization history

  • The Synchronizer log

To view the local synchronization history, right-click the local machine icon and select View Local Synchronization History; this opens the Synchronization History dialog box. (See Figure 24.32.) It shows you details about the exchange of information between the local replicas.

Viewing local synchronization history.

Figure 24.32. Viewing local synchronization history.

To view the remote synchronization history, select the line joining two Synchronizers and choose View | Synchronization History to open the Synchronization History dialog box. If you want more information about any of the log entries, click Details to open the Synchronization Details dialog box. (See Figure 24.33.)

The Synchronization Details dialog box shows the details of a synchronization process.

Figure 24.33. The Synchronization Details dialog box shows the details of a synchronization process.

Working with Synchronization Properties

You can also view properties of the selected Synchronizer. To do this, double-click the Synchronizer and the Replica Properties window appears. This tabbed dialog box gives you important information about the selected Synchronizer.

Note

Jet 3.5 and Access 97 support synchronization over the Internet or an intranet. You place a replica on a server and use the Replication Manager to synchronize, using a standard HTTP connection. This process is covered in Chapter 27, “Access and the Internet.”

Implementing Replication by Using Code

Most of the replication functions can be implemented by using code, but this isn't the easiest way to manage replication. However, sometimes you might want to implement aspects of the replication process with code so that you can better control the process, and its interface, from within your application.

Making a Database Replicable by Using Code

The following routine renders a database replicable by using code:

Sub MakeReplicable(strTargetDB As String)
    Dim db As Database
    Set db = DBEngine(0).OpenDatabase(strTargetDB, True)
    db.Properties.Append db.CreateProperty("Replicable", _
         dbText, "T")
    db.Close
End Sub

This routine accepts the path to any database as a parameter. It opens up the database exclusively, then appends the Replicable property to the database. This property contains a text value (dbText) set to True.

Flagging an Object as Local

Unless you do something special, all objects in a database are included in the replication process. The following code illustrates how to flag a database object as local. It sets the KeepLocal property of the tblEmployee table to True.

Sub MakeLocal()
    Const errPropNotFound = 3270
    Dim db As Database
    Dim tdf As TableDef
    On Error GoTo MakeLocal_Err

    Set db = CurrentDb
    Set tdf = db.TableDefs!tblEmployee
    tdf.Properties("KeepLocal").Value = "T"

    Exit Sub
MakeLocal_Err:
    If (Err = errPropNotFound) Then
        tdf.Properties.Append tdf.CreateProperty("KeepLocal", dbText, "T")
    Else
        MsgBox Error
    End If
End Sub

Notice that the code is set up to handle the error that occurs if the object, in this case the tblEmployee table, doesn't already have a KeepLocal property. The error handler appends the property to the object at runtime, and the code then sets the object's KeepLocal property to True.

Creating a Replica by Using Code

A new replica can be created with code by using the MakeReplica method. The code looks like this:

Sub MakeReplica(strRepCopy As String)
    Dim db As Database
    Set db = CurrentDb
    db.MakeReplica strRepCopy, ""
    db.Close
End Sub

This code accepts a parameter containing the path and filename for the replica. The MakeReplica method is executed on the database object, and the parameter name becomes the replica's name. The last parameter indicates whether the replica is created as read-only.

Creating a Partial Replica Using Code

You can also create a partial replica using VBA code, as follows:

Example 24.1. Creating a partial replica.

Sub CreatePartialReplica(strOriginal As String, _
      strReplica As String, _
      strTable As String, _
      strFilter As String)

   Dim db As Database
   Dim tdf As TableDef
   Dim intCount As Integer

   'Open Original Database
   Set db = OpenDatabase(strOriginal)
   'Make Replica Database with dbRepMakePartial constant
   db.MakeReplica strReplica, "Great Replica", dbRepMakePartial
   'Close Original Database
   db.Close

   'Open Replica Database
   Set db = OpenDatabase(strReplica, True)
   Set tdf = db.TableDefs(strTable)
   tdf.ReplicaFilter = strFilter

   'Loop through each table definition
   'If table is a Foreign table then set its PartialReplica
   'property to True
   For intCount = 0 To db.Relations.Count - 1
      If db.Relations(intCount).ForeignTable = strTable Then
         db.Relations(intCount).PartialReplica = True
         Exit For
      End If
   Next intCount
   'Populate Partial Replica
   db.PopulatePartial strOriginal
   db.Close

End Sub

The code begins by creating an empty replica with no filters and no data records. It then sets a filter for a specific table in the database. The PartialReplica property of the table relationships between the selected table and the tables it's related to is set to get records only from the child tables that meet the parent filter. Finally, the partial replica is populated from the full replica.

Synchronizing a Database by Using Code

At times, you might want to finish the synchronization process by using VBA code. The following routine synchronizes the current database with the database whose name is passed as a parameter. The constant dbRepImpExpChanges indicates that you want to perform a two-way synchronization.

Sub Synchronize(strDBToSync As String)
    Dim db As Database
    Set db = CurrentDb
    db.Synchronize strDBToSync, dbRepImpExpChanges
    db.Close
End Sub

Handling Conflicts by Using Code

You can also handle conflicts by using code. What you do when a conflict is identified is determined by the business needs of your users.

Sub IdentifyConflicts()
    Dim db As Database
    Dim tdf As TableDef
    Dim rstErr As Recordset
    Set db = CurrentDb
    For Each tdf In db.TableDefs
        If Len(tdf.ConflictTable) Then
            Set rstErr = db.OpenRecordset(tdf.ConflictTable)
            Do While Not rstErr.EOF
                Debug.Print rstErr.Fields(0).Value
                rstErr.MoveNext
            Loop
            rstErr.Close
        End If
    Next td
End Sub

This routine goes through each table, determining whether something is in the table's ConflictTable property. If the ConflictTable property has something in it, a recordset is opened from the Conflict table. The routine loops through each record of the Conflict table, displaying the value of the first field in the Debug window.

Practical Examples: Managing the Time and Billing Application with Replication

You must make a decision about whether it's necessary to implement replication in the Time and Billing application. It could be very useful if, for example, you have many consultants who work in the field and need to enter client, project, billing, and expense information while on the road. Using what you've learned in this chapter, you can make sure all changes made to each consultant's copy of the database are sent to the main server database each time the consultant dials into the office.

Replication can also be used so that the data managed by the Time and Billing application is backed up during the day, which minimizes the chance of data loss or downtime. Finally, you might want to implement replication in the Time and Billing application to distribute the work load over a few servers in your organization.

The potential benefits of using replication with the Time and Billing application are many. With what you have learned in this chapter, you must decide whether replication is appropriate for your application and how it can best be used in your organization.

Summary

Replication is a very complex and robust Access feature. It can be used at the most basic level to synchronize changes between two databases, or, in an enterprise-wide application, to synchronize changes between many machines on a WAN (Wide Area Network). The easiest, but least robust, way to implement replication is by using the Access user interface or the Windows 95 Briefcase. However, with the Replication Manager, you can schedule and manage synchronization activity, as well as handle the most complex of replication topologies. Finally, by using code, you can customize the behavior of your application's synchronization activities.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.122.4