Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to lock a file geodatabase (or only a single Mosaic dataset) at the beginning of a python script (and release it in the end).. I looked and looked and couldn't find any explicit arcpy command to do this.. Is it even possible to tell the gdb to lock itself? Or is the locking mechanism works autonomously?

share|improve this question
as far as I know it is managed by the software, I think if you did lock and then try to perform any operation it would say lock exists and error you out. – Brad Nesom Jun 17 '13 at 14:44
Do you need to be able to unlock it too? (That's a more common problem.) – Kirk Kuykendall Jun 17 '13 at 20:32
See a related blog post here. – Kirk Kuykendall Jun 18 '13 at 4:06

Are you looking to lock it for editing rows or editing schema? There are different kinds of fgdb locks.

Have you looked at the ISchemaLock interface?

It looks like for python you can check to see if there is a lock using this code and then do your operations that will lock the schema (like adding a field)

# Test if a schema lock can be applied, and if so, add a new field
if arcpy.TestSchemaLock(data):
    arcpy.AddField_management(data, "Flag", "LONG")

The amount of time that you lock the schema is meant to be kept to a minimum.

share|improve this answer
your link is highlighting a .NET option, not python. – artwork21 Jun 17 '13 at 20:10
Thanks Darlene, but I was looking for a more Transactional method i.e add a field, calculate some stuff (that doesn't lock the GDB by default) and then commit the changes to the GDB without worrying someone else changed my data during the calculations.. – Pavel Tarno Jun 19 '13 at 13:02

If you are using ArcGIS for Desktop 10.1 (you have not specified your version), then the Editor class of the Data Access module (arcpy.da) looks like it may meet this requirement.

The Editor class allows use of edit sessions and operations to manage database transactions.

Edits are temporary until saved and permanently applied to your data. You can also quit an edit session without saving your changes.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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