How to create a replica in a connected environment (ArcObjects .NET 10.6 SDK)
ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Managing data > Working with feature data > Distributed geodatabases > Replication > How to create a replica in a connected environment (ArcObjects .NET 10.6 SDK)

How to create a replica in a connected environment


Summary
This topic shows how to create a replica in a connected environment. A connected environment is where both replica geodatabases are connected on the same local area network (LAN) or wide area network (WAN) during replica creation.

Creating a replica in a connected environment

Complete the following steps to create a replica using ArcObjects:
  1. Connect to a geodatabase to host the parent replica and connect to a geodatabase to host the child replica. This requires initializing a GeoDataServer object for each connection. GeoDataServer objects allow access to a geodatabase on a LAN or a WAN through ArcGIS for Server. For more information about initializing a GeoDataServer, see How to initialize a GeoDataServer object.
  2. Call the following methods by pasting them into an application and passing in the following parameters:
Method
Parameters
gdsParent
One of the GeoDataServers initialized in Step 1. This is the GeoDataServer that hosts the parent replica.
gdsChild
The other GeoDataServer initialized in Step 1. This is the GeoDataServer that hosts the child replica.
replicaName
The name of the replica to be created. This name cannot already be used in either replica geodatabase.
accessType
Specifies whether to create a two-way, one-way, or checkout replica.
featureDataset
The fully qualified name of the feature dataset to replicate. See the following note.
geometry
The replica geometry. Only features that intersect this geometry will be included in the replica. If null is provided, all features are replicated.
registerOnly
False means that the child does not have the data. True means that the data exists in both geodatabases and new replicas should be registered for this data. In typical cases, set this to false.
useArchiving
True means that archiving will be used to track changes for one-way replication. This capability was added at ArcGIS 10. False means that versioning will be used to track changes for one-way replication.
Although this example can only be used to replicate a feature dataset and its contents, the code can be altered to accept feature classes and tables.
See the following code example:
[C#]
// Creates a replica of all data in a feature dataset.
public void CreateFeatureDatasetReplica(IGeoDataServer parentGDS, IGeoDataServer
    childGDS, String replicaName, esriReplicaAccessType accessType, String
    featureDataset, IGeometry geometry, Boolean registerOnly, Boolean useArchiving)
{
    try
    {
        // Set and expand the replica datasets.
        IGPReplicaDataset gpReplicaDataset=new GPReplicaDatasetClass();
        gpReplicaDataset.DatasetType=esriDatasetType.esriDTFeatureDataset;
        gpReplicaDataset.Name=featureDataset;
        IGPReplicaDatasets gpReplicaDatasets=new GPReplicaDatasetsClass();
        gpReplicaDatasets.Add(gpReplicaDataset);
        IGPReplicaDatasets gpReplicaDatasetsExpand=parentGDS.ExpandReplicaDatasets
            (gpReplicaDatasets);

        // Set the replica description.
        IGPReplicaDescription gpReplicaDesc=new GPReplicaDescriptionClass();
        gpReplicaDesc.ReplicaDatasets=gpReplicaDatasetsExpand;
        gpReplicaDesc.ModelType=esriReplicaModelType.esriModelTypeFullGeodatabase;
        gpReplicaDesc.SingleGeneration=(accessType ==
            esriReplicaAccessType.esriReplicaAccessNone);
        gpReplicaDesc.QueryGeometry=geometry;
        gpReplicaDesc.SpatialRelation =
            esriSpatialRelEnum.esriSpatialRelIndexIntersects;

        // Set the replica options.
        IGPReplicaOptions2 replicaOptions=new GPReplicaOptionsClass();
        replicaOptions.AccessType=accessType;
        replicaOptions.ChildReconcilePolicy =
            esriReplicaReconcilePolicyType.esriReplicaResolveConflictsNone;
        replicaOptions.ParentReconcilePolicy =
            esriReplicaReconcilePolicyType.esriReplicaResolveConflictsNone;
        replicaOptions.IsChildFirstSender=true;
        replicaOptions.RegisterReplicaOnly=registerOnly;
        replicaOptions.UseArchiving=useArchiving;

        // Create the replica.
        IReplicationAgent replicationAgent=new ReplicationAgentClass();
        replicationAgent.CreateReplica("", parentGDS, childGDS, replicaName,
            gpReplicaDesc, replicaOptions);
    }
    catch (COMException comExc)
    {
        throw new Exception(String.Format(
            "Create replica errored: {0}, Error Code: {1}", comExc.Message,
            comExc.ErrorCode), comExc);
    }
    catch (Exception exc)
    {
        throw new Exception(String.Format("Create replica errored: {0}", exc.Message)
            , exc);
    }
}
[VB.NET]
' Creates a replica of all data in a feature dataset.

Public Sub CreateFeatureDatasetReplica(ByVal parentGDS As IGeoDataServer, ByVal childGDS As IGeoDataServer, ByVal replicaName As String, ByVal accessType As esriReplicaAccessType, ByVal featureDataset As String, ByVal geometry As IGeometry, ByVal registerOnly As Boolean, ByVal useArchiving As Boolean)
    
    Try
    ' Set and expand the replica datasets.
    Dim gpReplicaDataset As IGPReplicaDataset=New GPReplicaDatasetClass()
    gpReplicaDataset.DatasetType=esriDatasetType.esriDTFeatureDataset
    gpReplicaDataset.Name=featureDataset
    Dim gpReplicaDatasets As IGPReplicaDatasets=New GPReplicaDatasetsClass()
    gpReplicaDatasets.Add(gpReplicaDataset)
    Dim gpReplicaDatasetsExpand As IGPReplicaDatasets=parentGDS.ExpandReplicaDatasets(gpReplicaDatasets)
    
    ' Set the replica description.
    Dim gpReplicaDesc As IGPReplicaDescription=New GPReplicaDescriptionClass()
    gpReplicaDesc.ReplicaDatasets=gpReplicaDatasetsExpand
    gpReplicaDesc.ModelType=esriReplicaModelType.esriModelTypeFullGeodatabase
    Dim singleGeneration As Boolean
    If accessType=esriReplicaAccessType.esriReplicaAccessNone Then
        singleGeneration=True
    Else
        singleGeneration=False
    End If
    gpReplicaDesc.SingleGeneration=singleGeneration
    gpReplicaDesc.QueryGeometry=geometry
    gpReplicaDesc.SpatialRelation=esriSpatialRelEnum.esriSpatialRelIndexIntersects
    
    ' Set the replica options.
    Dim replicaOptions As IGPReplicaOptions2=New GPReplicaOptionsClass()
    replicaOptions.AccessType=accessType
    replicaOptions.ChildReconcilePolicy=esriReplicaReconcilePolicyType.esriReplicaResolveConflictsNone
    replicaOptions.ParentReconcilePolicy=esriReplicaReconcilePolicyType.esriReplicaResolveConflictsNone
    replicaOptions.IsChildFirstSender=True
    replicaOptions.RegisterReplicaOnly=registerOnly
    replicaOptions.UseArchiving=useArchiving
    
    ' Create the replica.
    Dim replicationAgent As IReplicationAgent=New ReplicationAgentClass()
    replicationAgent.CreateReplica("", parentGDS, childGDS, replicaName, gpReplicaDesc, replicaOptions)
    Catch comExc As COMException
    Throw New Exception(String.Format("Create replica errored: {0}, Error Code: {1}", comExc.Message, comExc.ErrorCode), comExc)
    Catch exc As Exception
    Throw New Exception(String.Format("Create replica errored: {0}", exc.Message), exc)
    End Try
    
End Sub






To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing Deployment licensing
ArcGIS Desktop Standard ArcGIS Desktop Standard
ArcGIS Desktop Advanced ArcGIS Desktop Advanced
Engine Developer Kit Engine: Geodatabase Update