AUTOMATING STAR AND HUB SYNCHRONIZATION

A simple example demonstrates how you can code synchronizations between replicas in a star and hub topology. It's assumed that you already have code that writes the path to any new replica created in a table called Replicas, and you define which replica is the hub.

The table Replicas has two fields:

  • ReplicaPath. A string pathname to each replica in the replica set.

  • Hub. A Boolean: “Yes” if it's the hub; otherwise, “No.”

The code simply creates a recordset from the Replicas table, and then loops through the records. If the current record doesn't point to the hub, synchronize by using ReplicaPath.

The code in Listing 23.5 is behind a button named cmdSyncAllReplicas on the Synchronize Star & Hub Topology form.

Listing 23.5. Chap23.mdb: Synchronizing Star and Hub Replicas
Private Sub cmdSyncronizeAllReplicas_Click()
    ' Synchronize replicas in a star & hub topology
    ' The ''Replicas'' table stores the path to the replica
    ' and a Y/N if it is the hub replica

    ' This example has four entries in the ""Replicas"" table :
    ' c:	empdb1.mdb - the hub
    ' c:	empdb2.mdb
    ' c:	empdb3.mdb
    ' c:	empdb4.mdb

    ' This example expects this database is saved in c:	empdb1.mdb

    Dim rep As New JRO.Replica
    Dim conn As New ADODB.Connection
    Dim rsReplicas As New ADODB.Recordset

    conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data source=c:	empdb1.mdb;"
    Set rep.ActiveConnection = conn

    rsReplicas.Open "Replicas", conn, adOpenKeyset, adLockOptimistic
    Do Until rsReplicas.EOF
        ' Loop through replicas, synching with each
        If rsReplicas!Hub = False Then ' Hub can''t sync with itself
            rep.Synchronize rsReplicas!ReplicaPath, ,jrSyncModeDirect
            MsgBox (rsReplicas!ReplicaPath & " synchronized")
        End If
        rsReplicas.MoveNext
    Loop

    rsReplicas.Close
    MsgBox ("Synchronization complete")

End Sub

Caution

You may have already noticed that the MSysReplicas table already contains the path to each replica in the replica set. It's tempting to use these values rather than create your own, but that would be unwise. Microsoft provides no guarantee that system tables will maintain their format between releases. If your code relies on values in MSysReplicas, your code might not work in future releases of Access. Also, with the new replica visibilities, you might not be synchronizing your entire replica set.


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

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