Select to view content in your preferred language

Trying to edit a layer in a versioned SDE GDB in a Python stand-alone script

6489
10
Jump to solution
07-17-2013 12:47 PM
JaimeMcKeown
New Contributor II
Hello everyone,

I am trying to do a simple edit using Calculate field on a layer in a versioned SDE GDB. I've gotten past a few errors, but now have ran into a new one that I can seem to get past. The error is "Objects in this class cannot be updated outside an edit session". I'm trying to use arcpy.da.Editor, but I seem to be missing something.  Any ideas would be greatly appreciated!

fc = "Database Connections\\CCENTGIS_SCLFinal_PRSCL_test.sde\\prscl_test.SCLADMIN.GMSCL\\prscl_test.SCLADMIN.sclarc" workspace = "Database Connections\\CCENTGIS_SCLFinal_PRSCL_test.sde"  arcpy.MakeFeatureLayer_management(fc, "sclarc_layer")  edit = arcpy.da.Editor(workspace)  edit.startEditing() edit.startOperation()  with arcpy.da.Editor(workspace) as edit:     arcpy.CalculateField_management("sclarc_layer", "STRNAME", "!strname!.strip", "PYTHON_9.3", "")  edit.stopOperation() edit.stopEditing(True) 
Tags (2)
0 Kudos
10 Replies
JaimeMcKeown
New Contributor II
It finally works!  The example you just sent worked once I set the workspace only to the database and not the dataset.  The longer way that I was trying also works after I changed the object on the statement.  I did'nt realize that I needed to use a differenct object from the one I used above.  My boss that hasn't been available for 2 days final came to help as well.

Here are both scripts that finally worked.

import arcpy
workspace = "Database Connections\\PRSCL_TEST_SCLAdmin.sde"
fc = "prscl_test.SCLADMIN.sclarc"
arcpy.env.workspace = workspace
arcpy.MakeFeatureLayer_management(fc, "sclarc_layer")
with arcpy.da.Editor(workspace) as edit:
    arcpy.CalculateField_management("sclarc_layer", "STRNAME", "!strname!.upper()", "PYTHON_9.3", "")


import arcpy
workspace = "Database Connections\\PRSCL_TEST_SCLAdmin.sde"
fc = "prscl_test.SCLADMIN.sclarc"
arcpy.env.workspace = workspace
arcpy.MakeFeatureLayer_management(fc, "sclarc_layer")
edit = arcpy.da.Editor(workspace)
edit.startEditing(False, True)
edit.startOperation()
with arcpy.da.Editor(workspace) as fieldEdit:
    arcpy.CalculateField_management(fcLayer, "STRNAME", "!strname!.upper()", "PYTHON_9.3", "")
edit.stopOperation()
edit.stopEditing(True)


Thank you so much for your help!!!