I am trying to get a list of current SQL Server SDE versions so that I can then loop through these versions to get a count of features in each version. I believe the error that I get (below) may be a formatting error due to the backslashes and/or quotation marks in non-DBO-owned versions, but I cannot figure out a solution. Help?
Code:
import arcpy,os
from arcpy import env
arcpy.env.overwriteOutput = True
python_connection = r"Database Connections\inv2018_python.sde"
arcpy.env.workspace = python_connection
arcpy.MakeFeatureLayer_management("DNA_18","lyr_DNA_18")
# Get a list of versions
versions = arcpy.ListVersions(python_connection)
print versions
for version in versions:
print version
# change to this version
arcpy.ChangeVersion_management("lyr_DNA_18","TRANSACTIONAL", version)
# update feature layer to reference this new version
arcpy.MakeFeatureLayer_management("DNA_18","lyr_DNA_18")
# print a count of features in the feature layer
print arcpy.GetCount_management("lyr_DNA_18")
Python Interpreter:
>>>
[u'dbo.DEFAULT', u'DBO.QA', u'DBO.EDITS', u'"ISP\\TOBY".TR_Edits', u'DBO.DNA_EDITS', u'"ISP\\MANDERSON".MA', u'"ISP\\BRIAN".BO', u'"ISP\\PLAILIKITNONT".PL', u'DBO.SC', u'"ISP\\JEANNE".jeanne']
dbo.DEFAULT
342
DBO.QA
342
DBO.EDITS
342
"ISP\TOBY".TR_Edits
Traceback (most recent call last):
File "<module1>", line 17, in <module>
File "c:\program files (x86)\arcgis\desktop10.3\ArcPy\arcpy\management.py", line 16043, in ChangeVersion
raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000800: The value is not a member of ISP\BRIAN | .BO | ISP\JEANNE | .jeanne | ISP\MANDERSON | .MA | ISP\PLAILIKITNONT | .PL | ISP\TOBY | .TR_Edits | dbo.DEFAULT | DBO.DNA_EDITS | DBO.EDITS | DBO.QA | DBO.SC.
Failed to execute (ChangeVersion).
>>>