Microsoft KB Archive/258539

= MOD2000: The Syntax for Synchronization Using Microsoft Jet and Replication Objects =

Article ID: 258539

Article Last Modified on 12/17/2002

-

APPLIES TO


 * Microsoft Office 2000 Developer Edition

-



This article was previously published under Q258539



This article applies only to a Microsoft Access database (.mdb).

Advanced: Requires expert coding, interoperability, and multiuser skills.



SUMMARY
This article shows you how to use direct, indirect, and Internet replication with Microsoft Jet and Replication Objects (JRO) to synchronize database replicas. The article assumes that you already have installed and configured Microsoft Replication Manager on your Internet server for synchronizing replicas over the Internet.



MORE INFORMATION
You can use the Synchronize method of JRO to synchronize database replicas. The Synchronize method uses the following syntax: Replica.Synchronize(Target [, SyncType] [, SyncMode]) The Target parameter is a string argument that specifies the path and file name of the replica with which to synchronize, the name of the Synchronizer that manages the target replica, or the name of the Internet server that contains the target replica.

The SyncType parameter is optional. It is an Enum argument that specifies the type of synchronization to perform. The default value for the SyncType parameter is jrSyncTypeImpExp. The following values are valid for the SyncType parameter:

Synchronization is bidirectional by default. For more control over the direction of the exchange, you can use one of the other exchange constants jrSyncTypeImport or jrSyncTypeExport.

The SyncMode parameter is optional. It is an Enum argument that specifies the method of synchronization. The default value for the SyncMode parameter is jrSyncModeIndirect. Other values that can be used are for SyncMode:

The replica identified in the Target parameter must be part of the same replica set. If both replicas have the same ReplicaID property setting or are Design Masters for two different replica sets, the synchronization will fail.

When the SyncMode is indirect, the value of the Target parameter must be a Synchronizer name. Jet Replication creates MSG files that are sent to the Dropbox folder. The Synchronizer that manages that target replica will then pick up the changes and apply them to the replica that it is managing. For indirect synchronization to work correctly, Microsoft recommends that a Synchronizer is running on both the local computer and the target computer.

When the SyncMode is Internet, the value of the Target parameter must be a URL (Uniform Resource Locator) address instead of a UNC path (local area network path). An error will occur if a URL is specified in the Target parameter and the SyncMode parameter is not jrSyncModeInternet.

When the SyncMode is direct, both replicas are opened simultaneously and synchronized. Over a WAN or a remote dialup network, reliability and performance are improved by using indirect synchronization.

You can also synchronize a SQL Server replica that is in a replica set that has both SQL Server and Jet databases by setting the Target parameter to ServerName.Database.Publication and by performing a direct (jrSyncModeDirect) synchronization. An error will occur if the SyncMode is other than direct.

If the ReplicaType of a replica is set to jrRepTypeNotReplicable, replication will fail because the database that this is assigned to is not considered to be replicated.

Replication Manager (Replman) is required for installation and configuration of the Synchronizer, and Microsoft recommends that Replication Manager is used to monitor the status for indirect and Internet synchronizations. For Access 2000, Replication Manager is only available in Microsoft Office 2000 Developer. Earlier Developer editions also included their version of Replication Manager.

Synchronize Method Examples
The following three examples demonstrate the Synchronize method. For each of these examples to work, the database must have a reference to the Microsoft Jet and Replication Objects 2.x Library, where the library that is referenced is version 2.1 or later.

Direct Synchronization Example
This example demonstrates how to update changes between a Design Master and a replica: Public Sub DirectSync Dim repDM As New JRO.Replica Dim repReplica As New JRO.Replica Dim con As New ADODB.Connection

'Open the database. con.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data source=C:\Program Files\Microsoft Office\" & _ "Office\Samples\Northwind.mdb;"

repDM.ActiveConnection = con

'If a replica of the database exists, it is deleted. If (Dir("C:\Program Files\Microsoft Office\" & _ "Office\Samples\Replica of Northwind.mdb") <> "") Then Kill ("C:\Program Files\Microsoft Office\" & _             "Office\Samples\Replica of Northwind.mdb") End If

'Create a new replica of the database. repDM.CreateReplica "C:\Program Files\Microsoft Office\" & _ "Office\Samples\Replica of Northwind.mdb", _ "Replica1 for Northwind.mdb", _ jrRepTypeFull, jrRepVisibilityGlobal

'New values are put into Table1. On Error Resume Next

con.Execute "DROP TABLE Table1"

On Error GoTo 0

con.Execute "CREATE TABLE Table1 (Field1 Int)" con.Execute "INSERT INTO Table1 VALUES (1)" con.Execute "INSERT INTO Table1 VALUES (2)"

'Synchronize the values. repDM.Synchronize "C:\Program Files\Microsoft Office\" & _ "Office\Samples\Replica of Northwind.mdb", _ jrSyncTypeImpExp, jrSyncModeDirect End Sub

Indirect Synchronization Example
This example demonstrates how to use the Synchronize method with indirect synchronization: Public Sub IndirectSync Dim repDM As New JRO.Replica

repDM.ActiveConnection = "C:Program Files\Microsoft Office\" & _ "Office\Samples\Northwind.mdb"

'Replace the following  with the actual name of the 'Synchronizer that manages the replica with which you want to   'exchange data. repDM.Synchronize "", jrSyncTypeImpExp, _ jrSyncModeIndirect End Sub

Internet Synchronization Example
This example demonstrates how to use the Synchronize method for Internet synchronization. Note that before synchronization begins, the Internet replication Setup must be completed.

When supplying the URL address of the Internet server, the code does not have to supply the full path to the replica on the server. For example, if your Internet server name is "MyServer" and has a replica that is named "Northwind.mdb" in a shared "Scripts" folder, you can use the following syntax: Sub InternetSync Dim rep As JRO.Replica

Set rep = New JRO.Replica

rep.ActiveConnection = "C:\Program Files\Microsoft Office\" & _ "Office\Samples\Northwind.mdb" rep.Synchronize "http://MyServer", jrSyncTypeImpExp, _ jrSyncModeInternet

Set rep = Nothing End Sub Regardless of the synchronization mode (direct, indirect, or Internet), if the database is secured, you must add the User ID and Password information and the location of the workgroup file to the ActiveConnection string, for example: rep.ActiveConnection = _ "Data Source=C:\Program Files\Microsoft Office\" & _ "Office\Samples\Northwind.mdb;" & _ "Password=test;User ID=test;" & _ "Jet OLEDB:System database=C:\Secured.mdw"

