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).
>>>
Solved! Go to Solution.
ESRI Support got back to me: "We were able to determine that the behavior you are experiencing where the version string for an OS authenticated user appears to be split between the username and version name in the Change Version tool, is a known software defect in ArcGIS for Desktop 10.2.1 to and 10.3.1. The issue persists when using the tool in Python script where such versions do not get parsed in correctly. The good news is that the bug was fixed in version 10.4 ..."
I've taken the liberty of copying and pasting your code into the python Syntax Highlighter....
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")
This looks like a new arcpy method in ArcGIS Pro, and I haven't played with it at all yet, but at least you get to see how the syntax highlighter works....
Thanks, that's pretty. Now if we can just get it to work!
Here you can see how the Change Version parameters look in Model Builder. It has separated, rendering incorrect, all non-DBO owned version names into Domain\Username and .VersionName. I'm at a loss how to fix this.
From the help: Each input feature layer or table view will have its workspace modified to connect to the requested version. So, what is the practical application of this tool? I guess I just don't get it.....
This is the first step of a more complex code I've written to check for specific edits of concern prior to automating nightly reconcile, post and delete of child versions. If I cannot figure out a way to loop through existing child versions, I will not be able to automate this process as I'd intended.
ESRI Support got back to me: "We were able to determine that the behavior you are experiencing where the version string for an OS authenticated user appears to be split between the username and version name in the Change Version tool, is a known software defect in ArcGIS for Desktop 10.2.1 to and 10.3.1. The issue persists when using the tool in Python script where such versions do not get parsed in correctly. The good news is that the bug was fixed in version 10.4 ..."
That's a really weird response: the only way I find a reference for it is the ArcGIS Pro help. No mention of it in earlier versions...
Thanks for your help!