I am writing an ArcGIS Pro toolbox tool using Python. I am using arcpy.management.Delete(fc) to delete a feature class and it works on File Geodatabase (*.gdb). However it does not work for a SDE database. I open the Pro and add the feature classes from a SDE database and add my toolbox on Catalog pane. When I try to delete some feature classes, it fails with error message
" ERROR 000601: Cannot delete ..\SECore_Tools_Testing_sde.DBO.point_windmill. May be locked by another application. Failed to execute (Delete)."
For investigating the functionality and access, I use Pro built-in geoprocessing tool "Delete" to delete some feature classes and it works successfully. I can see the deleted feature classes are gone from map even they were on the map.
Please help! Thanks!
I'll investigate. Meanwhile, could you please share snippet of your code?
Thanks, Nobbir
GP Team.
Hello, Nobbir, here is my code:
def process_feature_classes(workspace, fc_list):
arcpy.env.workspace = workspace
try:
featureclass_count = 0
for i, fc in enumerate(fc_list):
feature_count = int(arcpy.GetCount_management(fc).getOutput(0))
if feature_count == 0:
arcpy.Delete_management(fc)
except:
arcpy.AddError("Failed to process_feature_classes. {0}\n{1}".format(sys.exc_info()[0], sys.exc_info()[1]))
I also tried arcpy.management.Delete(fc) and got the same results.
Hi Yu Luo, here are two topics that you can consult as to how to handle SDE data.
https://desktop.arcgis.com/en/arcmap/latest/manage-data/gdbs-in-sql-server/geodatabase-locks.htm
When you handle SDE data you need to be aware of whether data is locked or not. Delete will fail if you don't have proper permission to manipulate the data.