Getting the error "cannot open workspace" while using arcpy.da.Editor(arcpy.env.workspace) for a versioned data
Can anyone help on this.
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?
Thanks for ur reply.
Yes, It is editing manually with the standard license.
If you look at the second example down below on this page Editor—Help | ArcGIS Desktop you can see the sequence of commands you should use. Can you post your code?
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"
arcpy.CreateDatabaseConnection_management(path, connection, "ORACLE",instanse, "DATABASE_AUTH", "test",XXX, "SAVE_USERNAME", "",database, "TRANSACTIONAL",<version_name>,"")
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 arcpyimport osfc = '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 operationedit.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 changesedit.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
import arcpyimport osfc = '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 operationedit.startOperation()# Insert a row into the table.with arcpy.da.UpdateCursor(fc, ('Name')) as ucur: for row in ucur: row = '222' ucur.updateRow(row) # Failing at this case# Stop the edit operation.edit.stopOperation()# Stop the edit session and save the changesedit.stopEditing(True)
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
Hi Kamyaka Kasani ,
It looks like you are opening several thread that are related to the same issue? It is better to only post one, and if you have more information to help the original post, you can edit you post to add it (you can even change the title...but only if it help clarify...otherwise is can be confusing).
There are tips on posting Community News and Tips: How to ask questions and get answers and any code can be posted using Posting Code blocks in Esri GeoNet This help every one know if spacing is correct (critical for Python) and be able to refer to the same line number. (see Xander Bakker code blocks vs your code blocks)
Just for reference, I think the other related posts are:
The specified item was not found. (#748417)
The requested operation is invalid on a closed state (#748418)
The requested operation is invalid on a closed state (#748387)
and this one which is post #748389
Having the relative responses in one post with ovoid duplication and will help others find a solution in the future. If there are no responses to some of the other posts, you can actually delete them...but only do so if there is no information, or if it is already included in another post. Thanks
Retrieving data ...