I assume that you have the right license level available to start the editing on that workspace? Is it a Enterprise GDB (would require Standard or up). When you manually start editing on that workspace, does that work?
And make sure you are specifying
Path to the workspace to edit. Editor can edit only one workspace at a time
and not the FC. That sometimes is something that is overlooked. As Xander pointed out, check out the samples.
Here is my sample code
path = 'D:\\temp'
connection = "test1.sde"
tablePath = path + "\\" + connection
arcpy.env.workspace = tablePath
with arcpy.da.UpdateCursor(arcpy.env.workspace,[<field_name>], where) as cur:
# updatecursor stuff come here
First of all, is this a script that will only be run 1 time or do you want to run it multiple times? If multiple times, it would be better to use an existing connection or check if it has already bee created. Creating a sde connection on the fly, requires additional like having the Oracle client 32 bits (ArcMap) and/or Oracle client 64 bits (ArcGIS Pro) installed and working and tnsnames.ora and sqlnet.ora configured properly (to name a few requirements).
If you look at the sample code that both Rebecca and I mentioned earlier:
import arcpy import os fc = 'Database Connections/Portland.sde/portland.jgp.schools' workspace = os.path.dirname(fc) # Start an edit session. Must provide the workspace. edit = arcpy.da.Editor(workspace) # Edit session is started without an undo/redo stack for versioned data # (for second argument, use False for unversioned data) edit.startEditing(False, True) # Start an edit operation edit.startOperation() # Insert a row into the table. with arcpy.da.InsertCursor(fc, ('SHAPE@', 'Name')) as icur: icur.insertRow([(7642471.100, 686465.725), 'New School']) # Stop the edit operation. edit.stopOperation() # Stop the edit session and save the changes edit.stopEditing(True)
... you can see there is a sequence of steps to be followed:
What kind of business logic will you be applying inside the cursor?
I'm using Updatecursor logic all are working fine but while updating the row its getting failed at the statement
RuntimeError: The requested operation is invalid on a closed state
arcpy os fc workspace os path dirname fc edit arcpy da Editor workspace edit startEditing edit startOperation arcpy da fc ucur for row in ucur: row = '222' ucur.updateRow(row) # Failing at this case edit stopOperation edit stopEditing
It should have failed on the line before also:
row = '222'
This will not work since the index should be 0 and not 1. You only have 1 field.
and I don't think you have a featureclass and connection called like this:}
fc = 'Database Connections/Portland.sde/portland.jgp.schools'
Here is my code mxd = arcpy.mapping.MapDocument("CURRENT") for lyr in arcpy.mapping.ListLayers(mxd): if lyr.name == 'test': if lyr.supports("SERVICEPROPERTIES"): servProp = lyr.serviceProperties path = 'D:\\temp' connection = "ttene71.sde" fc = "test" where = 'OBJECTID = 1' #35585 arcpy.CreateDatabaseConnection_management(path,connection,"ORACLE",<instance>,"DATABASE_AUTH",<user_name>,<password>,"SAVE_USERNAME","",<password>,"TRANSACTIONAL",<version_name>,"") dbc = 'Database Connections//test1.sde' workspace = os.path.dirname(dbc) editor = arcpy.da.Editor(workspace) editor.startEditing(False,True) editor.startOperation() cursor = arcpy.da.UpdateCursor(lyr,['OBJECTID','NAME'], where) for row in cursor: row = '222' cursor.updateRow(row) # getting the error here del row del cursor editor.stopOperation() editor.stopEditing(True) del editor del mxd