1

I have a script that deletes a feature class and then recreates it. I've noticed that in ArcGIS Pro 2.0, as soon as a feature class is deleted, if there are any map layers that have that feature class as a data source, if they are visible, a schema lock error occurs. If they are turned off, they are automatically removed from the map (rather than simply remaining in the map with a broken data source).

It seems to happen both if I delete a data source while running a script, or if I do it in the python window. For example, in an ArcGIS Pro project, using the Python window, try:

arcpy.Delete_management(any feature class that is represented by a corresponding layer in the TOC)

If the layer is visible, you will get:

ExecuteError: ERROR 000464: Cannot get exclusive schema lock.  Either being edited or in use by another application.
Failed to execute (Delete).

If the layer is not visible, it is removed from the map. Is there a way to prevent this from happening? I would prefer an option to have a layer remain with a broken data source rather than be automatically removed.

3
  • Have you tried using code to make the Layer forget its data source prior to deleting the data that was its source?
    – PolyGeo
    Commented Aug 4, 2017 at 20:20
  • I have not tried that, but it theoretically should be possible using .updateConnectionProperties() with the last optional argument set to False. Its tedious to change this for every layer that references that feature class, then after deleting, to point all the layers back to the feature class.
    – spaine
    Commented Aug 4, 2017 at 20:25
  • 1
    Unless the table schema is being changed, you'd be far better off truncating it and repopulating.
    – Vince
    Commented Aug 4, 2017 at 22:32

1 Answer 1

1

Two suggestions are:

  1. Try using code (updateConnectionProperties()) to make the Layer forget its data source prior to deleting the data that was its source
  2. From @Vince:

Unless the table schema is being changed, you'd be far better off truncating it and repopulating.

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