How to synchronize a replica in a connected environment

This article describes how to synchronize a replica in a connected environment using ArcObjects. A connected environment is one in which both replica geodatabases are connected on a local area network (LAN) or a wide area network (WAN) during replica creation.
This article assumes that a replica has already been created and is ready to be synchronized.

Synchronizing a replica in a connected environment

The following steps describe how to synchronize a replica using ArcObjects. Before running the code, it is assumed that replicas already exist and you are ready to synchronize the changes.
  1. Connect to the geodatabase containing the parent replica and connect to the geodatabase containing the child replica. This requires initializing a GeoDataServer object for each connection. GeoDataServer objects allow you to access a geodatabase on a LAN or a WAN through ArcGIS Server. To see how to initialize a GeoDataServer, refer to How to initialize a geodataserver object.
  2. Call the following procedure. To do this, paste it into your application and call it passing in the following parameters:
One of the GeoDataServers that you initialized in Step 1.
The other GeoDataServer that you initialized in Step 1.
The name of the replica that you want to synchronize.
The policy that describes how conflicts will be handled when synchronizing.
Determines if you want to send the changes from the parent to the child or from the child to the parent.
True means that you want to define conflicts from the column level, while false means that you want to define conflicts from the object level.
See the following code:
// ++ Synchronizes a replica in a connected environment.
static void synchronizeReplica(IGeoDataServer parentGDS, IGeoDataServer childGDS,
    String replicaName, int conflictPolicy, int syncDirection, boolean columnLevel)
    throws Exception{
    // ++ Get the parent replica.
    IGPReplicas replicas = parentGDS.getReplicas();
    IGPReplica replica = new GPReplica();
    String baseName;
    int dotIndex;
    for (int i = 0; i < replicas.getCount(); i++){
        replica = replicas.getElement(i);
        dotIndex = replica.getName().lastIndexOf(".") + 1;
        baseName = replica.getName().substring(dotIndex, replica.getName().length() 
            - dotIndex);
        if (baseName.equalsIgnoreCase(replicaName))
    //++ Get the child replica.
    replicas = childGDS.getReplicas();
    IGPReplica replicaChild = new GPReplica();
    for (int i = 0; i < replicas.getCount(); i++){
        replicaChild = replicas.getElement(i);
        dotIndex = replicaChild.getName().lastIndexOf(".") + 1;
        baseName = replicaChild.getName().substring(dotIndex, replicaChild.getName()
            .length() - dotIndex);
        if (baseName.equalsIgnoreCase(replicaName))
    //++ Sync the replica.
    IReplicationAgent repAgent = new ReplicationAgent();
    repAgent.synchronizeReplica(parentGDS, childGDS, replica, replicaChild,
        conflictPolicy, syncDirection, columnLevel);

Development licensingDeployment licensing
ArcGIS for Desktop StandardArcGIS for Desktop Standard
ArcGIS for Desktop AdvancedArcGIS for Desktop Advanced
Engine Developer KitEngine: Geodatabase Update