Select to view content in your preferred language

IReplicationAgent Question

566
5
01-07-2011 07:54 AM
LukeBadgerow
Deactivated User
We're working on a utility to automate (and move out of modelbuilder) our process for synchronizing our production SDEGDB with our publication SDEGDB, but I'm getting stuck when I actually run the synchronization utilizing the SynchronizeReplica() method (GeodatabaseDistributed.IReplicationAgent). 

I'm looping through both our pub and prod databases and catching the matching replicas but the method is attempting to look for the replica from a separately owned gdb AND it's adding the ID number for the parent replica to the name when it tries to run -- in this case it's trying to hit one of the child versions to get the replica and adding parentReplica.ID to the end of the replica name.

the relevant section from the stack trace:

System.Exception was unhandled
  Message="Create replica errored: Version not found [GCWWGIS.WaterReplicaToEngweb_21], Error Code: -2147215997"
  Source="AutomatedReconcileCsharp"
  StackTrace:
       at AutomatedReconcileCsharp.formBatchReconcile.SynchronizeReplica(IGeoDataServer parentGDS, IGeoDataServer childGDS, String replicaName, esriReplicationAgentReconcilePolicy conflictPolicy, esriReplicaSynchronizeDirection syncDirection, Boolean columnLevel) in C:\Documents and Settings\lbadgerow\My Documents\Visual Studio 2008\Projects\AutomatedReconcileCsharp\AutomatedReconcileCsharp\formBatchReconcile.cs:line 458
       at AutomatedReconcileCsharp.formBatchReconcile.SyncWithPub(IWorkspace sde) in C:\Documents and Settings\lbadgerow\My Documents\Visual Studio 2008\Projects\AutomatedReconcileCsharp\AutomatedReconcileCsharp\formBatchReconcile.cs:line 372

                IGPReplicas gpReplicas = parentGDS.Replicas;
                IGPReplica parentReplica = null;
                for (int i = 0; i < gpReplicas.Count; i++)
                {
                    // See if the unqualified replica name matches the replicaName parameter.
                    IGPReplica currentReplica = gpReplicas.get_Element(i);
                    String currentReplicaName = currentReplica.Name;
                    int dotIndex = currentReplicaName.LastIndexOf(".") + 1;
                    String baseName = currentReplicaName.Substring(dotIndex,
                        currentReplicaName.Length - dotIndex);
                    if (baseName.ToLower().Equals(replicaName.ToLower()))
                    {
                        parentReplica = currentReplica;

                        break;
                    }
                }

                // Check to see if the parent replica was found.
                if (parentReplica == null)
                {
                    throw new ArgumentException(
                        "The requested replica could not be found on the parent GDS.");
                }

                // Iterate through the replica of the child GeoDataServer.
                gpReplicas = childGDS.Replicas;
                IGPReplica childReplica = null;
                
                for (int i = 0; i < gpReplicas.Count; i++)
                {
                    // See if the unqualified replica name matches the replicaName parameter.
                    IGPReplica currentReplica = gpReplicas.get_Element(i);
                    
                    String currentReplicaName = currentReplica.Name;
                    int dotIndex = currentReplicaName.LastIndexOf(".") + 1;
                    String baseName = currentReplicaName.Substring(dotIndex,
                        currentReplicaName.Length - dotIndex);
                    if (baseName.ToLower().Equals(replicaName.ToLower()))
                    {
                        childReplica = currentReplica;
                        break;
                    }
                }

                // Check to see if the child replica was found.
                if (childReplica == null)
                {
                    throw new ArgumentException(
                        "The requested replica could not be found on the child GDS.");
                }
                // Synchronize the replica.
                parentReplica.Name = parentReplica.Name + "_21";
                IReplicationAgent replicationAgent = new ReplicationAgentClass();
                replicationAgent.SynchronizeReplica(parentGDS, childGDS, parentReplica,
                    childReplica, conflictPolicy, syncDirection, columnLevel);
            }
            catch (COMException comExc)
            {
                throw new Exception(String.Format(
                    "Create replica errored: {0}, Error Code: {1}", comExc.Message,
                    comExc.ErrorCode), comExc);
            }
0 Kudos
5 Replies
HeatherMcCracken
Esri Contributor
Can you try commenting out this line:

      parentReplica.Name = parentReplica.Name + "_21";

..and then try again. Is this successful?

This line is likely the one causing the issue.
The replica's name is already a property of the gpreplica object... you do not need to set it. And it looks like you are trying to rename the replica with the "_id" ....ie "_21" - I'm not clear why you are doing this? (and if you were trying to rename this is not the place to do it?)

Anyway, give this a shot and post back whether this helps or not?
And perhaps explain what you were trying to do with this line if I misunderstood.
thanks,
Heather
0 Kudos
LukeBadgerow
Deactivated User
Can you try commenting out this line:

      parentReplica.Name = parentReplica.Name + "_21";

..and then try again. Is this successful?

This line is likely the one causing the issue.
The replica's name is already a property of the gpreplica object... you do not need to set it. And it looks like you are trying to rename the replica with the "_id" ....ie "_21" - I'm not clear why you are doing this? (and if you were trying to rename this is not the place to do it?)

Anyway, give this a shot and post back whether this helps or not?
And perhaps explain what you were trying to do with this line if I misunderstood.
thanks,
Heather


Thanks for the response Heather.  I was attempting to rename the replica name with the id because of something that we had noticed when we viewed our error logs. 

As it turned out though both of us working on this project had been attempting to sync the database with our old method (modelbuilder) and our new method and somewhere along the line the new version created a replica under a different db owner that didn't get deleted.  When we cleaned it up on the Oracle side everything cleared up and runs smoother than we had expected.

thanks again

Luke
0 Kudos
HeatherMcCracken
Esri Contributor
Glad you got it going.
As an aside, replication internally uses the replica ID for system versions that we use to track the changes.  If you see message in the replica log, mentioning not being able to find a version (with an "_ID" in the name), this doesn't mean it's expecting the replica_name to include the ID, it's just the naming convention for the system version.
-Heather
0 Kudos
LukeBadgerow
Deactivated User
I figured that something like that was going on, but at the time I posted we were trying to limit any possible doubt as to what if...  I'm fairly certain that I had the solution coded in but commented out long before we sent out the call for help.

thanks again.
0 Kudos
LukeBadgerow
Deactivated User
So now it gets fun.  The GUI app that was completing the sync worked out well.  So we have been discussing the possibility of pushing this to one of our servers so that we can schedule the task to run without a user having to push go. 

However, when I ported the replication code to a console application I started to develop the following error:
Version not found [WATERSENT.WaterReplicaToEngweb_34], Error Code: -2147216556

which is the other side of the equation of the error that I was having before.  Code is identical, well not identical.  I added in code to synchronize with a couple of file geodatabases on our SOM machines, which doesn't work currently either, but that appears to be a separate issue.

I get a number of different error codes when I look at the GDB_REPLICALOG table for the associated replica id: 
error - 2147220959 which states: "Objects in this class cannot be updated outside an edit session [WATERSENT.SystemValve] " and appears to be related to the sde.state table because I can fix that by running synchronization to the sde database in question from our 9.2 box.

and the above mentioned 556 error.

again, we're talking about the exact code snippet from above.  Any guidance on where to look for a solution is greatly appreciated.  We're currently running an amalgam of fixes (python, catalog tree, gui code, sde commands, batch files) and we really want to get this to be a consistent process that we can schedule.
0 Kudos