ACC: How to Use the ReplicationConflictFunction PropertyLast reviewed: August 29, 1997Article ID: Q158930 |
The information in this article applies to:
SUMMARYAdvanced: Requires expert coding, interoperability, and multiuser skills. This article describes how to use the ReplicationConflictFunction property in a database replica set so that you can create a custom procedure to resolve synchronization conflicts.
MORE INFORMATIONWhen you use replicated databases in Microsoft Access, you may encounter synchronization errors from time to time. Microsoft Access includes a Conflict Resolver wizard to help you resolve those conflicts when they occur. However, you may want to create your own procedure to help users resolve synchronization conflicts. Also, the Microsoft Access Developer's Toolkit license agreement does not permit you to distribute wizards with your run- time applications; therefore, you must create your own conflict resolution procedure if your run-time application includes replicated databases. The ReplicationConflictFunction property enables you to use a custom procedure to resolve conflicts instead of using the Conflict Resolver wizard. The procedure you create to resolve conflicts must be in a replicable module in the Design Master.
Creating a Custom Conflict ResolverYour custom procedure must be able to process three types of errors:
Synchronization ConflictsSynchronization conflicts occur when one record in a table is updated at two or more different replicas. Even if the changes are made to different fields in the record, the Microsoft Jet database engine treats it as a conflict. The Jet database engine does not attempt to resolve the conflict. Instead, it uses an algorithm to select one version of the record as the official change, and it stores the other version in a conflict table. Conflict tables are named <tablename>_Conflict, where <tablename> is the table in which the conflict occurred. You can detect conflicts using Visual Basic code by looking for the ConflictTable property of a table. The following portion of a procedure checks for the existence of conflict tables in a replica database:
Sub ViewSyncConflict() Dim Db As DATABASE Dim Td As TableDef Dim i as Integer Set Db = CurrentDb ' Step backward through the TableDefs collection so you ' do not miss any tables when you delete conflict tables. For i = Db.TableDefs.Count - 1 to 0 Step -1 Set Td = Db.Tabledefs(i) If (Td.ConflictTable <> "") Then ' Open a recordset based on the conflict table. ' Insert code to do conflict resolution. ' Delete the conflicting record when you are done. ' Delete the conflict table when all its records are deleted. ' Set the ConflictTable property to "". End If Next i End Sub Synchronization ErrorsSynchronization errors can come from at least four different sources:
Open the MSysErrors table to see what errors occurred. The following portion of a procedure displays the synchronization errors in the MSysErrors table:
Sub ViewSyncError() Dim Db As DATABASE Dim Rs As Recordset Dim MsgString As String On Error GoTo ErrorHandler Set Db = CurrentDb Set Rs = Db.OpenRecordset("MSysErrors", dbOpenSnapshot) Rs.MoveLast If Rs.RecordCount > 0 Then Rs.MoveFirst Do Until Rs.EOF ' Build the error message string. MsgString = "Table ID: " & Rs!TableGUID & vbCr MsgString = MsgString & "Record ID: " & Rs!RowGUID & vbCr MsgString = MsgString & "Operation: " & Rs!Operation & vbCr MsgString = MsgString & "Failed Because: " & Rs!ReasonText MsgBox MsgString Rs.MoveNext Loop End If ExitProc: Exit Sub ErrorHandler: ' If the MSysErrors table is empty... If Err.Number = 3021 Then Resume ExitProc ' display any other error that occurs. Else MsgBox Err.Description Resume ExitProc End If End Sub Design ErrorsA design error occurs when a local object exists with the same name as a replicable object in the Design Master. For example, if a user at a replica creates a local form called Form1, and you create a replicable form in the Design Master called Form1, synchronization fails. The design error is recorded in a system table called MSysSchemaProb. The records in MSysSchemaProb are automatically deleted when the conflict is resolved and the design change is successfully synchronized. The following sample procedure checks for the existence of the MSysSchemaProb table, and displays the design error:
Sub ViewDesignError() Dim Db As DATABASE Dim Rs As Recordset Dim MsgString As String On Error GoTo ErrorHandler Set Db = CurrentDb Set Rs = Db.OpenRecordset("MSysSchemaProb", dbOpenSnapshot) Rs.MoveFirst Do Until Rs.EOF ' Build the error message string. MsgString = "Operation: " & Rs!Command & vbCr MsgString = MsgString & "Failed Because: " & Rs!ErrorText MsgBox MsgString Rs.MoveNext Loop ExitProc: Exit Sub ErrorHandler: ' If the MSysSchemaProb table does not exist. If Err.Number = 3078 Then Resume ExitProc ' If the MSysSchemaProb table is empty. ElseIf Err.Number = 3021 Then Resume ExitProc ' Display any other error that occurs. Else MsgBox Err.Description Resume ExitProc End If End Sub Putting It All TogetherOnce you have decided how you want to handle each type of synchronization error, create the custom function to use when conflicts occur. The following example combines the sample procedures in each of the earlier sections into a single function:
Function MyCustomFunction() ViewSyncConflict ViewSyncError ViewDesignError End Function Setting the ReplicationConflictFunction PropertyYou can set the ReplicationConflictFunction property programmatically or through the user interface. When you set the property programmatically, you may have to add ReplicationConflictFunction to the Properties collection of the database first, and then set its value.
Setting the ReplicationConflictFunction Programmatically
Setting the ReplicationConflictFunction Through the User Interface
ARTICLE-ID: Q138828 TITLE : ACC95: Microsoft Jet Replication White Paper Available on MSL ARTICLE-ID: Q164553 TITLE : ACC97: Jet 3.5 Replication White Paper Available on MSL Keywords : kbprg PgmHowTo Version : 7.0 97 Platform : WINDOWS Hardware : x86 Issue type : kbhowto |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |