Synchronization Conflicts

During the synchronization of replicas errors may occur. An error may be caused when the same record is updated in two members of the replica set and Microsoft Jet attempts to synchronize the two versions.

The following custom project illustrates how you can use the Replication command on the Tools menu in the Microsoft Office Access user interface to create and synchronize replicas. To learn about conflicts during the synchronization of replicas, we will create two replicas, Replica_England.mdb and Replica_France.mdb, and enter some conflicting data into the same record in both of these replicas.

Part II

©Custom Project 18-1: Replication via Microsoft Access User Interface

Part 1: Creating a Replica Named Replica_England.mdb

1. Open another copy of Microsoft Access with the Design Master DM_Northwind.mdb file that you created in Hands-On 18-1.

2. Choose Tools | Replication | Create Replica. In the Filename text box, enter Replica_England.mdb as the name of the new replica and click OK.

3. Microsoft Access displays a Creating Replica message box. When the process of creating a new replica is finished, you are asked whether you want to close and reopen the database. Click Yes in response to this message. Access reloads the Design Master DM_Northwind database. You may need to click Open in the Security Warning message to complete the loading process.

Part 2: Creating a Replica Named Replica_France.mdb

1. Choose Tools | Replication | Create Replica. In the Filename text box, enter Replica_France.mdb as the name of the new replica and click OK.

2. Microsoft Access displays a Creating Replica message box. When the process of creating a new replica is finished, you are asked whether you want to close and reopen the database. Click Yes in response to this message. Access reloads the Design Master DM_Northwind database. You may need to click Open in the Security Warning message to complete the loading process.

Part 3: Making Changes in the Replica_England Database

1. Exit Access, closing the Design Master DM_Northwind database.

2. Switch to Windows Explorer. Locate the Replica_England.mdb database file that you created in step 2 of Part 1 above. Double-click this file to open it.

3. In the Customers table, locate the customer record Around the Horn. Type 98051 in the Postal Code field for this record. Click on any other record to ensure that the data you entered is saved.

4. Close the Customers table.

5. Exit Access, closing the Replica_England.mdb database file.

Part 4: Making Changes in the Replica_France Database

1. Switch to Windows Explorer. Locate the Replica_France.mdb database file that you created in Part 2, step 1 above. Double-click this file to open it.

2. In the Customers table, locate the customer record Around the Horn. Type 98053 in the Postal Code field for this record. Click on any other record to ensure that the data you entered is saved.

Creating and Manipulating Databases with ADO

3. Close the Customers table.

4. Exit Access, closing the Replica_France.mdb database file. Part 5: Synchronizing Replicas

1. Start Access and load the Design Master DM_Northwind database.

2. Choose Tools | Replication | Synchronize Now.

3. When the Synchronize Database dialog box appears (see Figure 18-4), select the Replica_England.mdb file and click OK.

Figure 18-4: To synchronize the Design Master directly with the replica, use the Browse button to find the Replica_England.mdb file on your computer.

4. Click Yes in response to the message that the database must be closed prior to synchronization. Access reloads the Design Master DM_Northwind database. If the Security Warning message appears, click Open.

5. Click OK to confirm the completion of the synchronization process.

6. In the Design Master DM_Northwind database, choose Tools | Replication | Synchronize Now.

7. When the Synchronize Database dialog box appears (see Figure 18-5), select the Replica_France.mdb file and click OK.

Figure 18-5: To synchronize the Design Master directly with the second replica that you created in this custom project, use the Browse button to find the Replica_France.mdb file on your computer.

8. Click Yes in response to the message that the database must be closed prior to synchronization. Access reloads the Design Master DM_Northwind database. If the Security Warning message appears, click Open.

9. Click OK to confirm the completion of the synchronization process.

Synchronize Database "DM_Northwind'

mm

Synchf onije © Dredfy with Replca:

I c* |

¡03 v

[ Cancel ]

□ m3te-C:\..ARepka_Enaland.rndb'the Design Master

| Browse... j

In tbo Background with Al Synchronizers

In the Background with Synchroniser;

1

3

Synchronize Database "DM_Northwind'

mm

Synchronize © Drecti/ with Replca:

I c* |

303 v

[ Cancel ]

D Make -C:\.,ARepka_France,mdb' the Design Master

| Browse... j

In the Background with Al Synchronizers

In the Background with Synchroniser;

1

10. Microsoft Access displays a message indicating a synchronization problem (see Figure 18-6).

Figure 18-6: This message appears when Access finds out that a member of the replica set has a conflict with another member of the same replica set.

Figure 18-6: This message appears when Access finds out that a member of the replica set has a conflict with another member of the same replica set.

11. Click Yes in response to the above message to indicate that you want to resolve the conflicts now. The Microsoft Replication Conflict Viewer window appears (see Figure 18-7).

Figure 18-7: When you click Yes in response to the message shown in Figure 18-6, Access displays the Microsoft Replication Conflict Viewer, listing tables with conflicts.

Figure 18-7: When you click Yes in response to the message shown in Figure 18-6, Access displays the Microsoft Replication Conflict Viewer, listing tables with conflicts.

12. In the Microsoft Replication Conflict Viewer window, click the View button. Microsoft Access now displays a window specifying the reason for conflict (see Figure 18-8) and allows you to resolve the conflict.

Creating and Manipulating Databases with ADO

Creating and Manipulating Databases with ADO

Figure 18-8: This window with conflict details appears when you click the View button in the Microsoft Replication Conflict Viewer window (see Figure 18-7).

13. For this example, click Close to exit the Microsoft Replication Conflict Viewer for DM_Northwind.mdb - Customers (1) window without making any changes. Click Close again to close the Microsoft Replication Conflict Viewer (shown in Figure 18-7).

14. Close the Design Master DM_Northwind.mdb database file.

The steps you've just completed demonstrate how to create and synchronize replicas using the Microsoft Access user interface. By entering conflicting data in the same field of the same record you were able to see how Access can locate the problem area during the synchronization process and how you can resolve the data conflict using the Microsoft Replication Conflict Viewer window.

Hands-On 18-9 illustrates how you can use the ConflictTables property to find out whether any conflicts occurred during the synchronization of replicas. This property returns the name of the conflict table that contains the database records that conflicted during synchronization.

The conflict table has two columns. The first column contains the names of the tables where conflicts occurred and the second one lists the associated conflict table names. If there is no conflict table (or the database is nonreplicable), the ConflictTables property returns a zero-length string (" "). If you find out that the conflict occurred during synchronization, you should write a custom conflict-resolution procedure to handle the conflicts depending on your needs.

Part II

©Hands-On 18-9: Retrieving the Name of the Conflict Table

1. In the Acc2003_Chap18.mdb database file, insert a new module.

2. In the module's Code window, enter the Get_ConflictTables procedure as shown below.

Sub Get_ConflictTables()

Dim repDesignMaster As New JRO.Replica Dim rst As ADODB.Recordset Dim strPath As String strPath = CurrentProject.Path & "\DM_Northwind.mdb" repDesignMaster.ActiveConnection = strPath Set rst = repDesignMaster.ConflictTables With rst

If .EOF Then

Debug.Print "There are no conflicts."

Else

Do Until .EOF

Debug.Print "Table: " & rst.Fields(0) & vbCr _ ; "Conflict Table: " & .Fields(1) & vbCrLf .MoveNext

Loop .Close End If End With

Set repDesignMaster = Nothing Set rst = Nothing End Sub

3. Run the Get_ConflictTables procedure to find out the name of the conflict table.

Figure 18-9: The procedure in Hands-On 18-9 prints the location of the synchronization conflict table and the name of the table in which conflict has occurred.

Figure 18-9: The procedure in Hands-On 18-9 prints the location of the synchronization conflict table and the name of the table in which conflict has occurred.

Figure 18-10: The conflict table is hidden in the database window of the Design Master. To unhide it, choose Tools | Options. On the View tab, click the check box next to Hidden Objects.

Creating and Manipulating Databases with ADO

S Custoroers_Conflict: Table (Local)

EBB

Confll clRowGul d f Cu stornerlD | C o mpa nyN am e

ContaclName | ContaclTHle [ Address | City | Region

Posta iCode

*

Thomas Hardy Sales Representative 120 Hanovef Sq. London

98053

| Record: |TT | i | ► HmM of I

M\

Figure 18-11: The conflict table lists the conflicting record.

Figure 18-11: The conflict table lists the conflicting record.

0 0

Post a comment