0

I have a Python script that I want to turn into a scripting tool in ArcGIS. Part of the script creates several SDE database connection files, creates a versions using those connection files, and then deletes the connection files.

To delete the connection files, I'm using os.remove(connections). This works as expected in PyScripter and the Python window in ArcMap. However, when I create a scripting tool and try to run it, it returns the message, "System cannot find the path specified" in reference to this line.

I can modify the code to say

if os.path.exists(connections):
    os.remove(connections)

so that it will move on to the next step, but then I am left with a folder full of connection files when the tool is finished running.

Any suggestions?

I tried arcpy's Delete, but got Error 000601 that it may be locked by another application. I found this bug which says that this is a bug with arcpy.Delete_management in ArcMap 10.2.1 (which I am using), and suggests using os.remove() instead.

  • 1
    Have you tired the function arcpy.ClearWorkspaceCache_management() – spk578 Aug 24 '16 at 12:27
  • It'll disconnect idle enterprise geodatabase connections pro.arcgis.com/en/pro-app/tool-reference/data-management/… – spk578 Aug 24 '16 at 12:29
  • Unfortunately arcpy.ClearWorkspaceCache_management() isn't working for me either. It doesn't work in the standalone script either, though, so I probably just need to work on how I'm using arcpy.env.workspace. It's frustrating that os.remove() doesn't work since it's so simple and easily implemented. – 8313348673543 Aug 25 '16 at 12:12
1

Use the Clear Workspace Cache tool.

import arcpy
from arcpy import env
env.workspace = r"SDEConnection" 
env.workspace = "" 
arcpy.ClearWorkspaceCache_management(r"SDEConnection") 

If you do not specify a connection variable in the function all connections will be removed from the Cache

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.