Select to view content in your preferred language

Cannot Disconnect from an SDE Database using python geoprocessing scripts?

363
1
04-15-2011 08:02 AM
SteveWalker3
New Contributor
9.3sp1

In ArcCatalog, to disconnect from an SDE database, one simply right-clicks on the connection file and chooses disconnect. The database is closed and the .sde file goes back to having a red mark next to it.

I have not been able to achieve the same functionality using the python geoprocessing environment.

The code basically looks like this:


gp = arcgisscripting.create(9.3)
connection = ('/path/to/connection.sde')
gp.workspace = connection
# do some stuff

# when done doing some stuff, try to disconnect:
gp.ClearWorkspaceCache(connection)
gp.workspace = ""
gp = None


Even when the script cleanly exists, the connection remains active.
When I loop through dozens of databases, none of them disconnect and I have dozens of hung connections to dozens of sde databases, and users complaining that I have an active connection to their database, and ask me to please disconnect from it. I've had to tell them that I can't.

Ideas?
0 Kudos
1 Reply
VinceAngelo
Esri Esteemed Contributor
The doc on ClearWorkspaceCache says "Note: Clearing an ArcSDE workspace from the
ArcSDE workspace cache does not guarantee the connection to the ArcSDE server will
be disconnected..."  The example shows using env.workspace = "" *before*
arcpy.ClearWorkspaceCache(), so I'd suggest:

# when done doing some stuff, try to disconnect:
gp.workspace = ""

gp.ClearWorkspaceCache(connection)
gp = None


- V
0 Kudos