RuntimeError: cannot open feature class

14053
10
Jump to solution
05-26-2015 01:46 PM
CFrate
by
Occasional Contributor

My script below gets to the first feature class in the list and bails with:

RuntimeError: cannot open 'Roads'

I tested it in a file geodatabase and it worked as intended. Tried next with a connection to an SDE version and it failed.

User connection has full edit privileges to all GDB contents, so it should not be a permissions issue.

Anything additional I must do for an SDE geodatabase? Other thoughts?

    edit.startEditing(True)
    for fc in fclist:
        with arcpy.da.UpdateCursor(fc, ("OBJECTID", "OID@")) as cur:
            for row in cur:
                row[0] = row[1]
                cur.updateRow(row)
                del row
            del cur
    edit.stopEditing(True)
0 Kudos
1 Solution

Accepted Solutions
BillDaigle
Occasional Contributor III

I run update cursors on SDE fairly often without a problem. Nothing special about it from my perspective.  Are you passing the full path to the feature class, or setting the workspace and passing the fc name?  I almost always pass the full path and haven't had a problem.   

View solution in original post

0 Kudos
10 Replies
RebeccaStrauch__GISP
MVP Emeritus

Hi Carlo,

No answer for you right now, but just want to point out Posting Code blocks in the new GeoNet

For Python, spacing is important, so having the code posted as such will rule out GeoNet messing with the spacing.  You can go and edit you post.....and it will help for future posts too.

CFrate
by
Occasional Contributor

Thanks! I'd been looking everywhere for that.

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

If you don't have it bookmarked, type in "posting code" in any of the geonet search boxes....it's the post by Curtis Price​  

0 Kudos
BillDaigle
Occasional Contributor III

I run update cursors on SDE fairly often without a problem. Nothing special about it from my perspective.  Are you passing the full path to the feature class, or setting the workspace and passing the fc name?  I almost always pass the full path and haven't had a problem.   

0 Kudos
CFrate
by
Occasional Contributor

I set the workspace and passed the feature class name (list created using arcpy.da.walk). This worked with the test file GDB.

Are you suggesting that each feature class be set as the full path to it, and not just the fc name?

e.g. C:\\Users\\user1\\AppData\\Roaming\\ESRI\\Desktop10.2\\ArcCatalog\\user1@sdeProd\\sdeProd.DBO.PlanningZoning\\sdeProd.DBO.MunicipalLimits

?

0 Kudos
BillDaigle
Occasional Contributor III

Since the error is "Cannot open 'Roads'", it seems as though it might be having trouble finding the dataset.  I get the same error if I run the following lines:

import arcpy

with arcpy.da.SearchCursor('NonExistantFC',('ObjectId')) as cursor:
    for row in cursor:
        print row
0 Kudos
BillDaigle
Occasional Contributor III

You may want to try checking if the 'fc' exists.  If not, you know you're dealing with a pathing issue.

for fc in fclist:
    print fc, arcpy.Exists(fc)
CFrate
by
Occasional Contributor

Looks like that's the issue! Indeed Exists returned False for everything.

I've amended the paths accordingly, but now have run into a new runtime error: workspace already in transaction mode

There seem to be a few other threads referencing this error, so I'll have a look at those. Something to do with the fact that I'm editing in a version, perhaps.

edit:

Solution I found to this error was to remove any feature classes not registered as versioned. This was only one from my list, so it wasn't an issue.

Trying edit.startEditing(True, False) as recommended in other threads did not work.

Removing edit operation only solved the issue for some feature classes, but when it reached certain others, the process would fail.

JoshuaBixby
MVP Esteemed Contributor

Since "OID@" is a token for the ObjectID field, usually "ObjectID," what exactly are you attempting to do?  Does your feature class have a different unique identifier field than "ObjectID?"

You are starting an edit session, but it doesn't look like you have started an edit operation.  Before any updating can begin, an edit operation needs to be started as well.  See Editor example 2 from the Editor (arcpy.da) help.