3

So I made a script that takes data from an MSSQL database and inserts it into a featureclass. I added the script to a toolbox and am able to run the tool from within ArcMap 10.1. The problem is that I cannot re-run the tool. When I try and run it a second time, ArcMap crashes. I'll start ArcMap again, run the tool and when I try and run it the second time ArcMap crashes again.

By calling arcpy.AddMessage() coupled with time.sleep(5) I have narrowed the problem down to one line of code: pyodbc_cursor.execute("{call dbo.GetData(?)}",(DataID))

It seems like even though I close() and del all my pyodbc variables (connection, cursor, row) after I'm done with them the cursor is causing a problem when the script is executed the second time around.

This seems like some kind of bug between ArcMap, arcpy and pyodbc

  • 1
    Ok so unchecking the 'Run Python script in process' seems to fix this issue and I can run the script more than once without ArcMap crashing. I don't think this is a good answer since it doesn't really answer why ArcMap would crash on the second execution of a pyodbc cursor that was closed and deleted. – Samuel Henderson Mar 22 '13 at 18:54
  • Experienced the same with a generic python script. Where it was using the logging module and importing a logger, on the first run everything was OK. On second run the logger was NoneType Obect and crashed the script. Can confirm that ToolBox > right click script > Source > (Untick) Run Python script in Process solved the problem in ArcMap 10.6.1 – Jorge Mendes Dec 12 '18 at 16:26