Delete a feature class from a SDE database failed

1256
15
06-11-2020 11:45 AM
YuLuo
by
New Contributor II

When I tried to use arcpy.management.Delete(fc) to delete a feature class from a SDE database, it failed with error message " ERROR 000601: Cannot delete ..\SECore_Tools_Testing_sde.DBO.point_windmill.  May be locked by another application. Failed to execute (Delete)." 

Then I add the following code before delete the feature class:

edit = arcpy.da.Editor(arcpy.env.workspace)
edit.startEditing(False, True)
edit.startOperation()

arcpy.management.Delete(fc)

edit.stopOperation()

edit.stopEditing(True)

I got different error message " ERROR 000496: table is being edited. Failed to execute (Delete)."

Please help! Thanks.

0 Kudos
15 Replies
YuLuo
by
New Contributor II

Thank you for your help!

0 Kudos
YuLuo
by
New Contributor II

However, when I run Pro built-in geoprocessing tool "Delete" with feature class I am trying to delete on the map, I can delete it successfully. 

0 Kudos
RandyKreuziger1
Occasional Contributor

If it's part of the map I think you need to programmatically remove the layer from the map before you can delete it in your code.  Otherwise, your map has a shared lock on it.  

0 Kudos
YuLuo
by
New Contributor II

I start ArcPro without a template that shows blank Contents pane, no maps at all. Then I add my toolbox to the Catalog and run my tool. It gives me same error like the database "May be locked by another application". I think I have missed some code that should unlock SDE, but I don't know what is it.

0 Kudos
YuLuo
by
New Contributor II

The issue is due to the SDE process permission. After our SQL administrator assigned a different server, the issue is resolved. Thank you for the helps.

0 Kudos
YuLuo
by
New Contributor II

I am writing a python toolbox tool and run it in Pro.

0 Kudos