I am exporting code from arcpy.InsertCursor to arcpy.da.InsertCursor and I am getting the following error message:
Python Error occurred: workspace already in transaction mode
In the program I have reading cursor and two insert cursors.
curAppend = arcpy.da.InsertCursor(AGREEMENT_I, fieldnamesDelta) curUpdate = arcpy.da.InsertCursor(AGREEMENT_U, fieldnamesDelta) for rowToday in curToday: agreementID = rowToday datetimeVal = rowToday if datetimeVal is not None and agreementID is not None: whereClause = '"AGMID" = %s' % (agreementID) srcYesterday = arcpy.da.SearchCursor(AGREEMENT, fieldnamesYesterday, whereClause) count = 0 for rowYesterday in srcYesterday: if rowYesterday == rowToday : count = count + 1 if rowYesterday != rowToday or rowYesterday != rowToday \ or rowYesterday != rowToday or rowYesterday != rowToday \ or rowYesterday != rowToday or rowYesterday != rowToday \ or rowYesterday != rowToday or rowYesterday != rowToday \ or rowYesterday != rowToday or rowYesterday != rowToday : print "Record for Update :", agreementID logging.info('Update ' + whereClause) curUpdate.insertRow(rowToday) if count == 0: print "Record for Insert :", agreementID logging.info('Insert ' + whereClause) curAppend.insertRow(rowToday) .....
Remember that each cursor locks the data that it accesses. I can't see in your code the source of the data in each cursor, but you can't search and insert the same GDB or table. You also have to delete cursors when your done with one to release the lock. This doesn't look like it might happen in your code, but that will trigger the same error.
there is a whole section on data locks towards the bottom of this link. It describes the conditions where they might occur and it is given in the context of differences with the old cursors
In Python, the lock persists until the cursor is released. Otherwise, all other applications or scripts could be unnecessarily prevented from accessing a dataset. A cursor can released by one of the following:
An edit session in ArcMap applies a shared lock to data during the edit session. An exclusive lock is applied when edits are saved. A dataset is not editable if an exclusive lock already exists.