[GIS] How to drop ArcSDE connection using Python scripting

arcgis-10.0arcpyenterprise-geodatabasepython

I want to be able to control connections to ArcSDE via python. Here is my script so far using ESRI's example.

import arcpy
from arcpy import env
env.workspace = r"SDEConnection" 
fcList = arcpy.ListFeatureClasses()
print str(fcList) + "\n"
env.workspace = "" 
arcpy.ClearWorkspaceCache(r"SDEConnection")
print arcpy.GetMessages() + "\n"

But this isnt working .. it crashes my Python window 🙁

Best Answer

According to the updated help, you need to use arcpy.ClearWorkspaceCache_management()

You can use the following code:

import arcpy
from arcpy import env
env.workspace = "c:/connectionFiles/Connection to gpserver.sde"
arcpy.ClearWorkspaceCache_management()

This answer has been derived from OP's comment on the question.