I'm having a great deal of difficulty overwriting files when using ArcSDE. The usual 'arcpy.env.overwriteOutput' method doesn't seem to work.

When I run this script:

import arcpy
from arcpy import env

env.workspace = "L:\\DRAINAGE\\D_GROUP6\\STAFF\\CJE\\EDRN_3.sde"

arcpy.env.overwriteOutput = True

selected_link = "L:\\DRAINAGE\\D_GROUP6\\STAFF\\CJE\\EDRN_3.sde\\VALLAHC.EDRN_LINK6"
q_fid = 39
join1 = "L:\\DRAINAGE\\D_GROUP6\\STAFF\\CJE\\EDRN_3.sde\\VALLAHC.join39"

arcpy.MakeFeatureLayer_management(selected_link, "feature_layer10") 
arcpy.SelectLayerByAttribute_management("feature_layer10", "NEW_SELECTION", '\"OBJECTID_1\" = {0}'.format(q_fid))

arcpy.SpatialJoin_analysis("feature_layer10", edrn_node, join1, "JOIN_ONE_TO_MANY", "#", "#", "CONTAINS")

I get the following error:

Runtime error <class 'arcgisscripting.ExecuteError'>: ERROR 000601: Cannot delete L:\DRAINAGE\D_GROUP6\STAFF\CJE\EDRN_3.sde\VALLAHC.join39.  May be locked by another application. Failed to execute (SpatialJoin).

I have attempted to get around this in a number of ways:

  1. versioning/not versioning the data.

  2. Checking/unchecking the overwrite geoprocessing operations box in geoprocessing options.

  3. Using 'arcpy.Delete_management()' to delete the join at the end of the script. But ArcSDE won't let me and outputs the same 000601 error.

Does anybody have any ideas on how to get around this?

My script works fine when I use shapefiles or a regular geodatabase. I'm thinking there must be something I've missed related to ArcSDE that I'm not aware of as I don't have much experience with databases.

  • 1
    Data is never stored "in ArcSDE" -- It's stored in a database through ArcSDE. You should therefore always specify which database in the question.
    – Vince
    Commented May 28, 2015 at 15:43

1 Answer 1


You won't be able to overwrite a feature class if it is locked in another application (such as when you have it open in ArcMap) or if any other user has accessed it.

If you would have 10.1, you can check what are the connections established to the geodatabase (Connections tab under Geodatabase Administration).

You could use arcpy:

  • You can use arcpy.AcceptConnections() to prohibit users to connect to the geodatabase when you perform data updates.

  • Use arcpy.ListUsers() to get currently connected users and then disconnect them with arcpy.DisconnectUser().

With 10.0, the best strategy would be to do the Spatial Join in the in_memory or in a temp geodatabase. Then use Delete Features GP tool and Append GP tool. This approach is the best because it doesn't involve deleting and creating new database objects which can be troublesome with respect to locks and other users potentially working with the data. To delete and append features you don't care about locking as you don't work with the object yet on the row level. You might consider even running Truncate Table GP tool which is faster it does not involve db transactions.

Another comment: use os.path.join(sde_workspace,fc_name) to construct the data path.

  • Thanks Alex, I've had a go and this seems to work in principle. Its disappointing that the necessary locks cannot be used in tandem with certain edits but I can see why this has to be the case. The problem I have now is that without the versioning used in SDE there is no way to guard against two people working on the same feature at the same time. haha
    – Geord359
    Commented May 28, 2015 at 16:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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