Hi to everybody,
I wrote a script that, daily, erases and recreates a bunch of layers (feature classes) and tables.
The script works pretty well and completes the process succesfully with no error messages, but...
... here and there (frankly I do not see a pattern in the system behaviour) hung up due to a lock in one of the layers supposed to be deleted.
I have to manually remove it: with ArcCatalog I just "manage" the layer's locks and remove the criminal one left by the previous script run.
I work with ArcGIS suite 10.1 (Desktop + SDE for SQLServer + Server)
Any idea?
Massimiliano
The piece of code I am posting is a failed attempt to remove the "hipothetical" lock programmatically...
...
# Process: Select
arcpy.AddMessage("13) Selecting Features from " + UQ_MP70temp + " to create " + UQ_MP70)
if arcpy.Exists(UQ_MP70):
arcpy.AddMessage(".13.a) Start Deleting process of " + UQ_MP70)
AF_workspace = workingGDB
user_name = "DBO"
AF_users = arcpy.ListUsers(AF_workspace)
icount = 0
for item in AF_users:
arcpy.AddMessage(str(item.ID) + " - " + item.Name + " - " + user_name + " - " + str(icount))
if icount == 0:
userid = item.ID
if item.Name == user_name and icount >= 1:
arcpy.DisconnectUser(AF_workspace, userid)
arcpy.AddMessage(".13.b) " + user_name + " successfully disconnected")
arcpy.AcceptConnections(AF_workspace, True)
arcpy.Delete_management(UQ_MP70)
arcpy.AddMessage(".13.c.1) UNLOCKED - " + UQ_MP70 + " successfully deleted")
else:
arcpy.Delete_management(UQ_MP70)
arcpy.AddMessage(".13.c.2) NO LOCK - " + UQ_MP70 + " successfully deleted")
icount = icount + 1
arcpy.Select_analysis(UQ_MP70temp, UQ_MP70, "FocosQueimadas_DBO_UQ_MP_co_15 = 3")
Hi Massimiliano,
Why don't you prevent users from connecting to the GDB, disconnect all users, finish your delete operations and allow users to connect again to the GDB? ArcGIS Help 10.1 Example 2.
arcpy.AcceptConnections(admin_workspace, False)
arcpy.DisconnectUser(admin_workspace, 'ALL')
<<Your delete operations>>
arcpy.AcceptConnections(admin_workspace, True)
Many thanks Riyas,
The problem is that while developing the script I run it on my developing machine and I am the only SDE user!
So, it looks like the lock remained from a previous run. But it is random! Sometimes no problem! Other times LOCK! and I am used to fix it manually. I already informed the technicians about the problem and the workaround.
However I like your idea and I will try it.
Thanks again!
Massimiliano