arcpy.TestSchemaLock

4524
8
Jump to solution
12-16-2015 09:11 AM
WayneBoras
New Contributor III

I have created a Python script to automate the maintenance process for our enterprise geodatabase. The script checks to ensure that there are no locks before performing the maintenance tasks (e.g. Compressing the database). I'm using arcpy.TestSchemaLock to check for locks on 200+ feature classes. TestSchemaLock returns False for more than 30 feature classes, indicating that locks exist. However, when I open ArcMap, right-click the connection file, select Administration > Administer Geodatabase, and go to the Locks tab, there are no locks found. The only user listed on the Connections tab is the admin user that I am connected as.

Are these phantom locks? How can they be removed? Is there an alternative way to check for locks? Checking for *.lock files works for a file geodatabase, but not an enterprise geodatabase.

We are using ArcGIS Server 10.1 + MS SQL Server + direct connect.

Thanks in advance.

Wayne

0 Kudos
1 Solution

Accepted Solutions
WayneBoras
New Contributor III

ESRI Support has confirmed that this is a bug in ArcGIS 10.1 which was fixed in 10.2. TestSchemaLock always returns False for un-versioned datasets.

Another interesting discovery is that the problem occurs only when connected as the SDE user. If I run TestSchemaLock as another user, it works fine.

View solution in original post

0 Kudos
8 Replies
WesMiller
Regular Contributor III

You could disconnect the users removing the locks DisconnectUser—Help | ArcGIS for Desktop

# set the workspace environment
arcpy.env.workspace = workspace


# No more users to connect to database
arcpy.AcceptConnections(workspace, False)


#Disconnect Users
arcpy.DisconnectUser (workspace, "ALL")
0 Kudos
WayneBoras
New Contributor III

Thanks, but there are no other connected users.

0 Kudos
WayneBoras
New Contributor III

I just discovered something interesting. All of the datasets which are locked also happen to be un-versioned. The documentation (see here: ArcGIS Help 10.1) doesn't say that TestSchemaLock is only meant for versioned datasets. I can skip the lock check for un-versioned datasets using arcpy.Describe(datapath).isVersioned. However, I would still like to know why the lock check fails for un-versioned datasets.

I should also correct the ArcGIS version in my original post -- we are using 10.1 SP1 (not just 10.1).

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

I am running ArcGIS 10.3.1 + SQL Server 2014 + direct connect, and arcpy.TestSchemaLock returns True for me with unversioned feature classes, as long as another process isn't accessing the data.  I don't know if the difference is our ArcGIS versions, DBMS versions, DBMS configurations, etc....  It might be worth googling around for "ArcGIS issues addressed" and see if there have been any issues addressed in 10.2.x or 10.3.x related to testing schema locks.

0 Kudos
WayneBoras
New Contributor III

Thanks Joshua. That's good to know.

0 Kudos
WayneBoras
New Contributor III

ESRI Support has confirmed that this is a bug in ArcGIS 10.1 which was fixed in 10.2. TestSchemaLock always returns False for un-versioned datasets.

Another interesting discovery is that the problem occurs only when connected as the SDE user. If I run TestSchemaLock as another user, it works fine.

0 Kudos
RhettZufelt
MVP Frequent Contributor
0 Kudos
WayneBoras
New Contributor III

Hi Rhett,

Thanks. I had seen that post but it doesn't apply to my situation. I actually had the opposite problem -- it was returning False when it should have been True.

Wayne

0 Kudos