I am writing a script to use an updatecursor. The feature class is locked so I am versioning the database, creating a feature layer, and reconciling versions. I have taken the skeleton for my script from this thread. Debugging RuntimeError: workspace already in transaction mode from arcpy.da.UpdateCursor and ArcSDE feature classes?

The main difference is that I already had an SDE connection file in my directory. Should this be re-created each time the script is executed to avoid this error?

__author__ = 'Administrator'

from arcpy import *
import GetSRConfig
import os
import time

def GetDateTimeString(n = None):
        """ format a datetime to string """
            s = time.strftime("%Y%m%d%H%M%S", time.localtime())
            s = time.strftime("%Y%m%d%H%M%S", time.localtime())
            if((isNumeric(n)==True) and ((n>4) and (n<14))):
               s = s[0:n]
               s = s[0:14]
        return s

def isNumeric(s):
    b = True
        i = float(s)
    except:    # not numericelse:    # numeric
        b= False
    return b

P6featureName = GetSRConfig.SDELayer
Parent = "dbo.DEFAULT"
version = "myVersion" + GetDateTimeString(12)
featureLyr = "lyr" + GetDateTimeString(12)

print version
# Server = ***
# Service = ***
user ="dbo"
# Pass = ***
# SDE = 'E:\C_Drive_files\Administrator'\311Request\data\ServiceRequest.sde'
temploc = ""
fil = "SDETempConn"

env.overwriteOutput = True

#Create Version
print "Creating version"
arcpy.CreateVersion_management (GetSRConfig.SDEConnFile, Parent, version, "PUBLIC")
VersionName = user.upper() + "." + version

#Create new connection
workspace = os.path.join (temploc, fil + ".sde")
print workspace
P6feature = os.path.join (workspace, P6featureName)
arcpy.MakeFeatureLayer_management (GetSRConfig.SDELayer, featureLyr)

#Start editing
print "Initiating editing"
edit = arcpy.da.Editor (GetSRConfig.SDEConnFile)
edit.startEditing ()

#Test Cursor
print "Testing cursor"
P6Cursor = arcpy.da.UpdateCursor (featureLyr, ["VehicleNam"])
for row in P6Cursor:
    print row[0]
del row
del P6Cursor

#Stop/save edits
print "Stopping editing"

#Switch to version
print "Switching version"
arcpy.ChangeVersion_management(featureLyr, "TRANSACTIONAL", Parent)

#Reconcile and post
print "Reconciling and posting"
arcpy.ReconcileVersions_management (GetSRConfig.SDEConnFile, "", Parent, VersionName, with_post = "POST", with_delete = "DELETE_VERSION")
  • Yes, you should create a new connection with the version... but I don't see why you need to do so, SDE allows multi-user editing. Is the data registered as versioned? Oct 15 '15 at 22:00
  • No the data isn't registered as version. Oct 15 '15 at 22:03
  • 2
    The state tree associated with versioning is database-wide (multiple versioned tables can have changes at the same state), but you can't perform versioned edits to a table which isn't registered as versioned, and you can't commit edits to a table which is locked by another session.
    – Vince
    Oct 15 '15 at 22:45
  • I too already had an SDE connection file, but a connect at esri told me to create the new one, hence why it's included in my answer. I haven't experimented with excluding it once I got the code working, however. Oct 15 '15 at 23:10
  • @EmilBrundage when creating the connection file, how should the parameters be set? My server is just an IP address, while I was assuming my service is SDE. My arcgis server sits on port 6080. I have tried using the IP address as the service name but I receive an error where it cannot connect. Please advise. Oct 15 '15 at 23:13

You might want to check your license manager or your connection to same.

I have just started experiencing this problem in the middle of a python coding session. Things were working fine until all of the sudden I started pulling this error during 'import arcpy'. Specifically on the env portion.

I have discovered that there is an issue between me and our license managers. I am VPN'd into our network. When I remote to my desktop, all is well. When I try to connect via ArcGIS Administrator to our two license managers, I get intermittent results.
I am the sysadmin for the LMs and when connected directly to them, they show no problem.

In my case, the issue is something related to the VPN tunnel and the LMs.


After spending hours for resolving this issue i have found following.

  1. Check if database is versioned or non versioned.
  2. Avoid using nested cursor. Make sure to release all cursors and row objects as soon as you are done with them.
  3. A small work around which i have used after struggling in nested cursor scenario:- I had created layer object like this: arcpy.SelectLayerByAttribute_management(inputFC, 'my_lyr', "\"FieldName\" = \'" + SearchValue+ "\'") and removed my search cursor. This served my purpose to avoid nested cursor scenario and i was started getting filtered objects then i used it to get my desire result set for(Both Insert and update operations).
  4. If database in non versioned then then make sure you use following code. edit.startEditing(True, False) edit.startOperation()
  5. Use With keyword for with arcpy.da.SearchCursor/arcpy.da.InsertCursor cursor. This will make sure that your memory release appropriately without using del keyword
  6. if edit.stopEditing()operation giving you hard time(SystemError: error return without exception set: ) then comment it.(Funny but fact is my script worked if i run code from standalone way ex: command prompt or pyscriptor however as soon as i converted my script as GP service it started giving me error, so i have commented edit.stopEditing() and moved on as data was saving in database), I believe its something with python version which is used in ArcMAP and ArcPy but never get the full explanation.
  • What do you mean by change parameter accordingly!? What do you change it to?
    – user125266
    Apr 16 '19 at 17:41
  • 1
    @Steve Since you would be doing edit operation in versioned database so you have option to set "undo" and "multiuser_mode" property.ESRI link. Apr 18 '19 at 5:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.