0

I have a python script which runs nightly to update a few domains in an Enterprise Geodatabase (Oracle). I'm using the arcpy.TableToDomain_management tool. The script works fine unless there are schema locks on the domain. In particular, if ArcMap is open with a layer that is using one of these domains, the script fails to update the domain.

The error returned is:

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

I have attempted to disconnect users, thinking that would work. The code to disconnect users is:

def dropUsers():
    userList = [user for user in arcpy.ListUsers(sde_workspace)]
    for user in userList:
        try:
            arcpy.DisconnectUser(sde_workspace, user.ID)
            print('Disconnecting user: {0}, userID: {1}.'.format(user.Name, user.ID))
        except Exception as e:
            print('Could not disconnect user: {0}, userID: {1}.'.format(user.Name, user.ID))
            print(e)
        finally:
            arcpy.AcceptConnections(sde_workspace, True)

sde_workspace in the above code is a path to a connection file using the sde account.

The code to actually update the domain is:

arcpy.TableToDomain_management(os.path.join(output_folder, '{}.csv'.format(workzone)),code_field='Code',description_field='Description',in_workspace=destination_workspace, domain_name=domain_name,update_option="REPLACE")

destination_workspace in the above code is a path to a connection file using the domain owner.

No matter what I try, I cannot update the domains. I should also add, that I tried the TableToDomain geoprocessing tool and got the same 000464 error. However, if I close ArcMap and ensure no one else has ArcMap open, and I don't disconnect users, it works fine.

I'm using ArcMap 10.8.

2
  • Do you have any map/feature services pulling from the database? If so you may have to stop those services before editing the domains. Commented May 21, 2021 at 3:29
  • I do, but they get disconnected. They were published without schema locks, so I was pretty sure they were not causing the lock. I figured it out and answered the question below.
    – Fezter
    Commented May 21, 2021 at 4:24

1 Answer 1

3

I have solved this. It turns out that part of my script reads the domains which need to be updated. The reason for this is that I only update the domains if they have changed.

It turns out that reading the domains creates another connection. When I then drop all connections, ArcGIS must get confused and thinks it's still open.

The solution is to omit this connection when I drop users. To do this, I look at connection time and omit the most recently connected user.

I've modified my dropUsers function accordingly:

def dropUsers():
    userList = [user for user in arcpy.ListUsers(sde_workspace) if user.Name in ('AMIS', 'READONLY')]
    userList.sort(key = lambda user:user.ConnectionTime) #Don't drop most recently connected user - this may be the user that is running this script
    popped_user = userList.pop()
    print('Not disconnecting user: {0}, userID: {1}, Connected at {2}'.format(popped_user.Name, popped_user.ID, popped_user.ConnectionTime))

    for user in userList:
        try:
            arcpy.DisconnectUser(sde_workspace, user.ID)
            print('Disconnecting user: {0}, userID: {1}, Connected at {2}'.format(user.Name, user.ID, user.ConnectionTime))
            logging.warning('Disconnecting user: {0}, userID: {1}, Connected at {2}'.format(user.Name, user.ID, user.ConnectionTime))
        except Exception as e:
            print('Could not disconnect user: {0}, userID: {1}, Connected at {2}'.format(user.Name, user.ID, user.ConnectionTime))
            logging.error('Could not disconnect user: {0}, userID: {1}, Connected at {2}'.format(user.Name, user.ID, user.ConnectionTime))
            print(e)
            logging.error(e)
        finally:
            arcpy.AcceptConnections(sde_workspace, True)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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