AnsweredAssumed Answered

Arcpy: cannot get exclusive schema lock even if I use arcpy.DisconnectUser method

Question asked by deriuv on Jun 12, 2018
Latest reply on Mar 26, 2019 by CFriese-esristaff

Hi, I'm trying to delete some coded values from a domain in arcpy, but my script fails due to a schema lock. I'm on an arcsde enterprise geodatabase in oracle.
To force user disconnection, i use the following method:



def getExclusiveLock(admin_workspace):
   if admin_workspace == '':

   hostName = socket.gethostname()

   # Look through the users in the connected user list and get the SDE ID.
   # Use the SDE ID to disconnect the user that matches the username variable
   users = arcpy.ListUsers(admin_workspace)
   for item in users:
      if hostName.lower() not in item.ClientName.lower():
         arcpy.DisconnectUser(admin_workspace, item.ID)

   arcpy.AcceptConnections(admin_workspace, False)



This is the code I use to delete the coded values:


workspaces = [r'myWorkspace1', r'myWorkspace2' ]

sde = [r'sdeWorkspace1', r'sdeWorkspace2']

sdeIndex = 0

for ws in workspaces:

   domainValues= {}

   for domain in arcpy.da.ListDomains(ws):
      if == 'myDomain':
         domainValues = domain.codedValues



   f = open(r'fileWithCodedValuesToDelete', 'rb')
   reader = csv.reader(f, delimiter = ';')
   for row in reader:


         arcpy.DeleteCodedValueFromDomain_management(ws, 'myDomain', int(row[0]))
         arcpy.AddCodedValueToDomain_management(ws, 'myDomain', int(row[0]), row[0] + ' - ' + row[1])
      except KeyError:
         print "Key {0} not found".format(row[0])
         arcpy.AddCodedValueToDomain_management(ws, 'myDomain', int(row[0]), row[0] + ' - ' + row[1])
      except UnicodeDecodeError:
         print "Decode error {0}".format(row[1])

   sdeIndex = sdeIndex + 1



The script always returns the error "cannot get exclusive schema lock", but then, opening arcatalog, I see that there are no users connected, but the sde user.


Does anyone know why I cannot acquire the lock?