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.
Thanks Ya'll for your comments....turns out there was an issue with the FC itself. I rebuilt the db and everything works regarding the DELETE....thanks again
I've never found a good way to get around this from python. Usually when my script fails (and I know nobody else should be using the database) I delete the locks on the database and then rerun the script. There is probably a less disruptive way - I'd be curious to find out.
Do either of these feature classes exist:
C:/GIS_Scripts/Update/OS@Connection.sde/database.DBO.FEATURES_update
C:/GIS_Scripts/Update/OS@Connection.sde/fc_Out2a
as that is what is being told to delete (in that order).
Otherwise, normally when data is locked, it is by another user OR a service that is consuming the feature class.
You need to make sure you stop any services that are using that feature class. If that isn't it, you can try to disconnect users from the database, and, maybe even block incoming connections while you do the delete.
R_
The dbo.features_update FC exists....
Thats the crazy thing there are no locks....
That is ALL the code that I am trying to use....is there something else that I am missing....
It almost appears that its creating its own lock when its trying to read if it exists....
I would try to delete the table using the Delete Geoprocessing tool in ArcGIS Pro to see if you can establish that it is related to something in your python code. Another possibility is something in the database itself has it locked. Our systems use MS SQL Server and I would guess there are things you could do in the MS SQL Server Manager that would lock up a table. I've never had a problem with the arcpy.Exists call leaving the object locked.
OK so its telling me its locked but I have already cleared the locks....there is no service hitting this db and its on a test box so nothing should be accessing it....
It keeps telling me its locked but when I check the DB and FC after it runs there are no locks?
for fc in fc_Delete:
fc_path = os.path.join(workspaceLocation, fc)
print fc_path
if arcpy.Exists(fc_path):
arcpy.DisconnectUser(r"C:/GIS_Scripts/Update/OSConnection.sde/", "ALL")
print fc_path + " exists"
if not arcpy.TestSchemaLock(fc_path):
print "Can't proceed - " + fc_path + " feature class is locked"
else:
arcpy.ClearWorkspaceCache_management()
arcpy.Delete_management(fc_path)
My first thought is are you using the connection for the data owner? Most of the time it will be the sde account. Not sure what your OS connection has available in terms of roles, but that is something to check as well.
Thanks will check that out....
Thanks Ya'll for your comments....turns out there was an issue with the FC itself. I rebuilt the db and everything works regarding the DELETE....thanks again