ArcPy -Replica - How to get the list of feature classes from replica name

3724
1
01-07-2016 03:17 AM
AnjithaSenarath5
New Contributor II

I am trying to buld a replica log and trying to get the list of feature classes in a replica

can get the list of replica but I can't access it's properties and see the list of feature classes

Here is the code I am trying to execute

import arcpy

import os,sys

sdeConnection = r"Database Connections/abc@GISEDIT.sde"

# Print the name of the replicas

  

file1=open('C:\\TEMP\\log.txt', 'w+')

for replica in arcpy.da.ListReplicas(sdeConnection):

    file1.write(replica.name+"\n")

   

   

   

I can get the list of replicas but can't get the properties> feature classes in those replicas . Any help ?

0 Kudos
1 Reply
JakeSkinner
Esri Esteemed Contributor

Hi Anjitha,

I was able to do this using the pyodbc module.  Ex:

import pyodbc

cnxn = pyodbc.connect('Driver={SQL Server Native Client 11.0};Trusted_Connection=yes;SERVER=SDE;DATABASE=VECTOR;')
cursor=cnxn.cursor()
cursor.execute("Select Dataset.value('(/GPReplica/Name)[1]', 'nvarchar(max)') AS 'Name', Dataset.value('(.)[1]', 'varchar(MAX)')\
                AS 'DatasetName' From dbo.GDB_ITEMS AS items INNER JOIN dbo.GDB_ITEMTYPES AS itemtypes ON\
                items.Type = itemtypes.UUID CROSS APPLY items.Definition.nodes\
                ('/GPReplica/GPReplicaDescription/GPReplicaDatasets/GPReplicaDataset/DatasetName') AS DataSets(dataset)\
                WHERE ITEMTYPES.Name = 'Replica'")
rows = cursor.fetchall()
for row in rows:
    print "Replicae Name: " + row[0] + ", Feature Class: " + row[1]

If your repository is owned by SDE, you will need to change dbo.GDB_ITEMS and dbo.GDB_ITEMTYPES to sde.GDB_ITEMS and sde.GDB_ITEMTYPES in the query (line 6).