AnsweredAssumed Answered

Workspace already in transaction mode - two cursors, different workspaces

Question asked by MollyKFoley on Oct 18, 2017
Latest reply on Oct 19, 2017 by MollyKFoley

**Edit** - I have since closed my python script and reopened it. Now when I run it, I get the error "Cannot open workspace" when edit = arcpy.da.Editor(arcpy.env.workspace) is called. I imagine this is because the SDE database is not versioned, so I have set edit.startEditing('False', 'True') and also tried edit.startEditing('False', 'False') however that does not solve the problem either.

 

I have a script that takes data from a shapefile (using a search cursor) and copies it to a SDE feature class (using an insert cursor after some data manipulation). Obviously, the shapefile is in a different workspace than the SDE feature class.

 

I've read that this error occurs because you need to do your nested cursor actions in an edit session, but that does not seem to solve my problem.

 

I don't think this has anything to do with registering layers with the SDE database as the feature class was created inside the SDE database using ArcMap, therefore it shouldn't need to be registered (right? My knowledge on registering things is limited). It's not versioned and will not be in the future as there is no need.

 

Here's the main portion of the script:

 

#Set the workspace to access feature classes in the HbMonitoringTest SDE database
arcpy.env.workspace = r'C:\Users\user\AppData\Roaming\ESRI\Desktop10.5\ArcCatalog\myServer_HbMonitoringTest.sde'
#Getting feature class from database
PatchesFC = "Patches"
#Get input shapefile from different workspace
InputFC = r'C:\Users\user\Desktop\GIS_Testing\HbtatTesting\ExpTestFC.shp'

#create fields variables and a few other things here
#Start editing session on the SDE database
edit = arcpy.da.Editor(arcpy.env.workspace)
edit.startEditing()
edit.startOperation()

with arcpy.da.SearchCursor(InputFC, scFields) as sCursor: #Search cursor acts on shapefile  
     for row in sCursor:
        rowList = list(row)
        PatchID = '{' + str(uuid.uuid4()).upper() + '}'
        ObserverID = None
        rowList.insert(2, PatchID)
        rowList.append(ObserverID)
        rowTuple = tuple(rowList)
        with arcpy.da.InsertCursor(PatchesFC, icFields) as iCursor: #Insert cursor acts on SDE database
            iCursor.insertRow(rowTuple)

#Stop editing session
edit.stopOperation()
edit.stopEditing('True')

Outcomes