Select to view content in your preferred language

000464: Cannot get exclusive schema lock. Either being edited or in use by another application or service.

3741
5
Jump to solution
01-10-2024 11:04 AM
Labels (3)
mazzouzi
Occasional Contributor

If you are encountering the error "Either being edited or in use by another application or service" in ArcGIS when working with a geodatabase file, it typically indicates that the geodatabase is locked by another process or user. This can happen when a dataset within the geodatabase is being edited or when there's a lingering lock from a previous operation.

you can use the "arcpy.da.Editor" class in ArcPy. This class provides a way to manage edit sessions.

Here's an example script that stops the current editing session:

 

import arcpy

def stop_editing(workspace):
    try:
        # Create an edit session
        edit = arcpy.da.Editor(workspace)

        # Stop the edit session
        edit.stopEditing(True)  # The True parameter saves the edits

        print("Editing session stopped successfully.")

    except Exception as e:
        print("Error stopping editing session: {}".format(str(e)))

# Specify the path to your geodatabase file
geodatabase_path = r"C:\Path\to\YourGeodatabase.gdb"

# Call the function to stop editing
stop_editing(geodatabase_path)

 

Replace "C:\Path\to\YourGeodatabase.gdb" with the actual path to your geodatabase file.

 

1 Solution

Accepted Solutions
mazzouzi
Occasional Contributor
import arcpy

def stop_editing(workspace):
    try:
        # Create an edit session
        edit = arcpy.da.Editor(workspace)

        # Stop the edit session
        edit.stopEditing(True)  # The True parameter saves the edits

        print("Editing session stopped successfully.")

    except Exception as e:
        print("Error stopping editing session: {}".format(str(e)))

def disconnect_users(workspace):
    try:
        # Disconnect all users from the SDE geodatabase
        arcpy.DisconnectUser(workspace, "ALL")

        print("All users disconnected successfully.")

    except Exception as e:
        print("Error disconnecting users: {}".format(str(e)))

def remove_locks(workspace):
    try:
        # Remove all locks from the SDE geodatabase
        arcpy.ClearWorkspaceCache_management(workspace)

        print("All locks removed successfully.")

    except Exception as e:
        print("Error removing locks: {}".format(str(e)))

# Specify the path to your SDE geodatabase
sde_geodatabase_path = r"Database Connections\YourSDEConnection.sde"

# Call the function to stop editing
stop_editing(sde_geodatabase_path)

# Call the function to disconnect users
disconnect_users(sde_geodatabase_path)

# Call the function to remove locks
remove_locks(sde_geodatabase_path)

View solution in original post

0 Kudos
5 Replies
TylerT
by
Frequent Contributor

@mazzouzi et al,

I am getting this exact error regularly on Enterprise Geodatabase sde path vice gdb file.  I can't get the arcpy.da.Editor stopEditing script above working on the Enterprise workspace, and it's not clear to me whether it should work in the Enterprise environment.  Should arcpy.da.Editor(workspace) stopEditing work on an Enterprise Geodatabase and if not, how can I programmatically release locks and connections on feature classes.  For now, I have been using ArcGIS Pro GUI to release the endless locks and connections, but it's time consuming.

Thank you,

Tyler

0 Kudos
mazzouzi
Occasional Contributor
import arcpy

def stop_editing(workspace):
    try:
        # Create an edit session
        edit = arcpy.da.Editor(workspace)

        # Stop the edit session
        edit.stopEditing(True)  # The True parameter saves the edits

        print("Editing session stopped successfully.")

    except Exception as e:
        print("Error stopping editing session: {}".format(str(e)))

def disconnect_users(workspace):
    try:
        # Disconnect all users from the SDE geodatabase
        arcpy.DisconnectUser(workspace, "ALL")

        print("All users disconnected successfully.")

    except Exception as e:
        print("Error disconnecting users: {}".format(str(e)))

def remove_locks(workspace):
    try:
        # Remove all locks from the SDE geodatabase
        arcpy.ClearWorkspaceCache_management(workspace)

        print("All locks removed successfully.")

    except Exception as e:
        print("Error removing locks: {}".format(str(e)))

# Specify the path to your SDE geodatabase
sde_geodatabase_path = r"Database Connections\YourSDEConnection.sde"

# Call the function to stop editing
stop_editing(sde_geodatabase_path)

# Call the function to disconnect users
disconnect_users(sde_geodatabase_path)

# Call the function to remove locks
remove_locks(sde_geodatabase_path)
0 Kudos
mazzouzi
Occasional Contributor

try this code may work for you 

0 Kudos
TylerT
by
Frequent Contributor

Thank you!  I will give this a go, and let you know.  Tyler

0 Kudos
TylerT
by
Frequent Contributor

@mazzouzi et al,

That code worked for me.  Thank you.  Is there a way to be more surgical? This operates on the entire geodatabase where ArcGIS Pro client manually operates locks at the table level.  

Tyler

0 Kudos