Personal Geodatabase Lockfile Won't Go Away

1610
11
06-19-2012 03:15 AM
RobinPearce
New Contributor
Environment: ArcEditor/ArcMap/Arc Catalog 10.0 with Python 2.6.5

Problem: Running a script from ArcCatalog to populate an existing PGDB table from a CSV. The table gets filled perfectly but on completion of the script, the database lockfile(.ldb) doesn't disappear. Row and rows objects are both deleted in the script, so what is still holding the database? To clear the ldb, I have to close down ArcMap, then open the mdb in Access and then close it again. This defeats the whole object of convenience of staying in an ArcMap session to do a quick visual check of data just imported from CSV.

Here is my code:

import arcpy, csv

TypeOfData = str(arcpy.GetParameterAsText(0))
inputCSVfile = str(arcpy.GetParameterAsText(1))
FeatureClassTable = str(arcpy.GetParameterAsText(2))
row,rows = None,None

rows = arcpy.InsertCursor(FeatureClassTable)
fieldname = ["Last_Update","Last_Update_By","Feature_ID","Survey_ID","Survey_ID_Ref","Survey_Name","Feature_Name","Feature_Desc",
             "Symbology_Code","Symbology_Name","Line_ID","Line_Name","Easting","Northing","Depth","Altitude","Time_Stamp",
             "Heading","Remarks"]

inputTxtFile = open(inputCSVfile,"rb")
reader = csv.reader(inputTxtFile)
ID = 0

try:
  for inrow in inputTxtFile.readlines():
    if ID>0:
      itemstr = inrow.split(",")
      x = itemstr[10]
      y = itemstr[11]
      z = itemstr[12]
      m = 0
      point = arcpy.Point(x,y,z,m,ID)
      pnt = arcpy.PointGeometry(point)
      row = rows.newRow()
      row.setValue("Shape",pnt)
      row.setValue(fieldname[0],itemstr[0])
      row.setValue(fieldname[1],itemstr[1])
      if itemstr[2]!='': row.setValue(fieldname[3],itemstr[2])
      if itemstr[2]=='': row.setValue(fieldname[3],0)
      row.setValue(fieldname[4],itemstr[3])
      row.setValue(fieldname[5],itemstr[4])
      row.setValue(fieldname[6],itemstr[5])
      row.setValue(fieldname[7],itemstr[6])
      row.setValue(fieldname[8],itemstr[7])
      row.setValue(fieldname[10],itemstr[8])
      row.setValue(fieldname[11],itemstr[9])
      row.setValue(fieldname[12],itemstr[10])
      row.setValue(fieldname[13],itemstr[11])
      row.setValue(fieldname[14],itemstr[12])
      row.setValue(fieldname[15],itemstr[13])
      row.setValue(fieldname[16],itemstr[14])
      row.setValue(fieldname[17],itemstr[15])
      row.setValue(fieldname[18],itemstr[16])
      rows.insertRow(row)
      if ID%500==0: arcpy.AddMessage(ID)
    ID += 1
    if ID>100: break
  arcpy.AddMessage(ID-1)  

except:
  if not arcpy.GetMessages() == "":
    arcpy.AddMessage(arcpy.GetMessages(2))

finally:
  inputTxtFile.close()
  if row:
    del row
  if rows:
    del rows


What is really annoying, the same script runs in debug mode in PythonWin - as soon as I close PythonWin, the lockfile goes - without exiting my ArcMap session. But I don't want to use this method to run data.

What do I need to do?

Rob Pearce
Tags (2)
0 Kudos
11 Replies
RobinPearce
New Contributor
I've updated my 'finally' clause:

  finally:
    inputTxtFile.close()
    del row
    del rows
    del FeatureClassTable
    del ID
    del TypeOfData
    del fieldname
    del inputCSVfile
    del inputTxtFile
    del inrow
    del itemstr
    del m
    del pnt
    del point
    del reader
    del x
    del y
    del z
    del csv
    arcpy.RefreshCatalog("C:\GeneralWorkData\ArcGIS Test Data\OGP_BP\Python_work\BP8719_TestPop.mdb")
    del arcpy


'pywin' is not included because I'm trying to run this outside PythonWin.  'RefreshCatalog' is hardwired to my test PGDB after I stumbled over an old reference to this problem in an archived thread ("Python :: DeleteRows() and Release Object Reference", 9/27/04).

It don't work. I still have to crash out of Arcmap, then open the PGDB in Access then exit Access, to remove the lock. Surely there must be a way to do this properly! And I repeat, PythonWin manages to do it with Arcmap/Catalog still running.

ATTENTION ESRI:   Are you still supporting PGDB file work?  If you are, please have someone come out, review this thread, and tell me EXACTLY what I need to know to resolve this lockfile problem. Our company has already spent weeks trying to migrate from VBA, which is no longer supported, to Python. Are we wasting our time trying to run a Python script from an ArcMap/Catalog window??  THANK YOU!

Those of you exhorting us to switch to FGDB - can you assure us we won't have lockfile problems with that system?

Rob Pearce
(fed up with having to google every ESRI problem)
0 Kudos
RobinPearce
New Contributor
Right - when I run my script and then add the data layer to the map window, I am able to close ArcGIS (saving the mxd), and my precious ldb lockfile disappears immediately. I don't have to open an Access session to clear it.

Does this ring any bells with anyone?

I am trying to contact the people who created PythonWin, in case they know what their software is doing. You never know, I might actually get an answer!

Rob P
0 Kudos