[GIS] RuntimeError: cannot open “feature class” with SearchCursor

arcgis-10.3arcpyenterprise-geodatabaseruntimeerror

I have a very simple script that isn't working.

import arcpy

workspace = "C:\\Users\\Work\\AppData\\Roaming\\ESRI\\Desktop10.3\\ArcCatalog\\master.sde"
arcpy.env.workspace = workspace

wire = "gis.DBO.wire"

with arcpy.da.SearchCursor(wire, "id") as cursor:
    for row in cursor:
        print row[0]

It returns RuntimeError: cannot open 'gis.DBO.wire'


UPDATED

I still haven't figured this out. I just did a repair on ArcGIS Desktop 10.3, and that didn't solve it. So, then I removed Python, and reinstalled it and it still doesn't work.

I have this script I've tried running in PyScripter and IDLE:

import arcpy
sde = "C:\\Temp\\Data.sde"
domains = arcpy.da.ListDomains(sde)

I get:

enter image description here

And, yes it is a valid sde connection.

If I do the exact same code above in the Python window of ArcCatalog it works fine.

Here's the IDLE error:

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    domains = arcpy.da.ListDomains(sde)
RuntimeError

Best Answer

I think the problem here is that you are treating the SearchCursor() like a geo-processing tool. Geo-processing tools can honour 1 or more environment settings (which you find out by looking at the help for the tool) and one such setting is workspace.

Nowhere on the help page for SearchCursor() does it state that Workspace is an environment setting that it honours. In fact I don't think it honours any! So you need to provide the full path because currently you are providing a string "gis.DBO.wire".

Related Question