Select to view content in your preferred language

ArcSDE/Oracle connection management from Python

949
1
01-23-2013 07:10 AM
JuanDeclet-Barreto
New Contributor
I am a user with non-admin rights on a versioned ArcSDE Oracle geodatabase. I am writing a Python 2.6 script, and running it in ArcGIS 10.0 SP4. The script opens a connection from an .SDE file. I need to do some connection management, since during the debugging process the script crashes, leaves open connections on the SDE server, and eventually I get schema lock error messages, requiring that the gdb admin kill the open sessions in the server. Is there a way to manage these connections from my Python script, and to remove them either at the end of a successful script or run, or within a finally clause in a try-catch-finally code block?
Tags (2)
0 Kudos
1 Reply
ChrisSnyder
Honored Contributor
Are you using cursors? If so, be sure to delete your cursor objects:

#in v9.3 and v10.0
try:
   searchRows = gp/arcpy.SearchCursor(blah, blah)
   for searchRow in searchRows:
      blah
   del searchRow, searchRows
except:   
   del searchRow, searchRows


In v10.1 you can use the with statement with the new .da cursors to ensure release of locks: http://resources.arcgis.com/en/help/main/10.1/index.html#//018w00000011000000
0 Kudos