I am trying to read my SDE database and then delete specific feature classes if they exist...
I keep getting error below....not sure whats up....do I need to make a different connection to the db?
ExecuteError: ERROR 000601: Cannot delete C:/GIS_Scripts/Update/OS@Connection.sde/database.DBO.FEATURES_update. May be locked by another application.
Failed to execute (Delete).
def main():
sqlPath = r"C:/GIS_Scripts/Update/OS@Connection.sde/"
fc_Delete = ["database.DBO.FEATURES_update","fc_Out2a"]
for fc in fc_Delete:
fc_path = os.path.join(sqlPath, fc)
print fc_path
if arcpy.Exists(fc_path):
arcpy.Delete_management(fc_path)
Solved! Go to Solution.
I got this Traceback from an exception from arcpy.management.Delete:
Traceback (most recent call last):
[...TRIMMED THE SAUSAGE-MAKING OF MY SCRIPTS...]
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 6977, in Delete
raise e
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 6974, in Delete
retval = convertArcObjectToPythonObject(gp.Delete_management(*gp_fixargs((in_data, data_type), True)))
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: ERROR 000601: Cannot delete <PATH_TO_SDE_FILE>\<DATABASE>.<SCHEMA>.<FEATURE_CLASS>. May be locked by another application.
Underlying DBMS error [42S02:[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Cannot drop the procedure 'DBO.i68_return_ids', because it does not exist or you do not have permission.] [<DATABASE>.<SCHEMA>.<FEATURE_CLASS>]
Failed to execute (Delete).
I had another table that I had created using non-Esri SQL. That table had a foreign key referencing my feature class. Because the table and FK were both created with SQL, I guess SDE doesn't know about them, so wasn't tracking them, and thus was unable to delete the feature class with another table referencing it. As soon as I dropped the FK, the error went away.
I know we're supposed to always use Esri tools to manage database objects related to feature classes, but this seems like such a basic thing that it surprised me that arcpy's Delete couldn't figure it out.