ListVersions: Not a valid SDE workspace.

719
5
10-05-2011 11:42 AM
DanNarsavage
Occasional Contributor
I've been beating my head against a wall for a couple days now & it's past time for me to ask for help.  I've got a script that I run from the command prompt that I want (among other things) to get a list of all versions in an SDE instance, loop through that list looking for a version with a particular name, and delete that version if it exists.  The code I wrote is as follows:

ParentConnection = "C:\\temp\\Basemap_Default_DC1.sde\\"  ## Actually set programmatically but this is what's pumped into my function
ParentConnection = ParentConnection.rstrip("\\")
arcpy.env.workspace = ParentConnection
VersionList = arcpy.ListVersions()
## arcpy.ListVersions(ParentConnection) yielded the same results 
for name in VersionList:
       if name.endswith("." + VersionName):    ## If a version with this name already exists then delete it
              arcpy.DeleteVersion_management(ParentConnection, name)
              break



When I call arcpy.ListVersions() (regardless of scope or the two different ways to specify the workspace as noted above), I get the following error:

Traceback (most recent call last):
  File "R:\Addressing\QualityControl\PythonFiles\CountywideNearAnalysis.py", line 121, in <module>
    raise inst
ValueError: ListVersions: Not a valid SDE workspace.


Can anyone shed some light on this?  The sde file exists and works correctly in ArcCatalog, furthermore this same code works in ArcCatalog's Python window.  Thanks.
Dan
0 Kudos
5 Replies
DanNarsavage
Occasional Contributor
It's worth noting here that arcpy.ListFeatureClasses() works as expected when I put that ahead of ListVersions in the code above.
0 Kudos
RussellBrennan
Esri Contributor
Dan,

Typically this message indicates that Python/ArcPy was not able to connect to the database. Double check that that specific connection file can be used to connect to the database. If you are using 3-tier (application server) connections double check that the service is running. If you are creating the connection file in the script, ensure that you are providing the correct username/password/version.

I don't know what you are doing earlier on in your script but I have seen some issues where the workspace gets cached and this prevents the connection from succeeding. Try running ClearWorkspaceCache_management prior to what you have provided and see if that helps.

You should be using this syntax:
arcpy.ListVersions(ParentConnection)


I was able to run your code on my machine and get a list of versions without issue.
0 Kudos
DanNarsavage
Occasional Contributor
Thanks Russell.  But as I said, the sde file exists and works correctly in ArcCatalog.  It even works correctly immediately before I try ListVersions--I put an extraneous ListFeatureClasses in my script immediately before the ListVersions.  The ListFeatureClasses succeeded and I was able to print the resulting list, then ListVersions crashed the script with the error message I posted earlier.

I do create the connection file earlier in the script and it works to retrieve several feature classes. In fact one of these feature classes is used in two "arcpy.Near_analysis" analyses that finish mere seconds before this ListVersions fails.

We use OS authentication here, so the username & password properties are both hard-coded to "#."  But the connection *WORKS*, both earlier in the script and manually after the script bombs, so I highly doubt that's the issue.

I'm almost sure that I've tried clearing the workspace cache before without success, but trying it again . . . watch it work this time . . . to be continued tomorrow . . .
0 Kudos
DanNarsavage
Occasional Contributor
Sure enough, clearing the workspace cache worked.  Thanks Russell!
0 Kudos
RussellBrennan
Esri Contributor
No problem, I am pleased that this worked for you.
0 Kudos