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?
-
2as 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 NesomJun 17, 2013 at 14:44
-
Do you need to be able to unlock it too? (That's a more common problem.)– Kirk KuykendallJun 17, 2013 at 20:32
-
See a related blog post here.– Kirk KuykendallJun 18, 2013 at 4:06
2 Answers
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? http://resources.arcgis.com/en/help/arcobjects-net/conceptualhelp/index.html#//0001000004qw000000
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")
http://resources.arcgis.com/en/help/main/10.1/index.html#//018v0000002m000000
The amount of time that you lock the schema is meant to be kept to a minimum.
-
-
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.. Jun 19, 2013 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.