mrskyp

Personal Geodatabase Lockfile Won't Go Away

Discussion created by mrskyp on Jun 19, 2012
Latest reply on Jun 22, 2012 by mrskyp
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

Outcomes