4

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
3
  • If you just call arcpy.ListFeatureClasses(), does it list gis.DBO.wire? "True" might be spurious in this case... And, do you have read/write access to that directory? Nov 29, 2015 at 5:16
  • Do you get this error message when calling your connection via Database connections: workspace = r"Database Connections\master.sde"?
    – GISGe
    Nov 30, 2015 at 7:35
  • I am suffering this issue in a random way: I have 3 scripts, each of them create the sde(same username, password and database) file, then use it for collecting some info from a table(same table). These scripts run every night, and from time to time, one of the scripts fail with this error. I used the verification for the table as mentioned by @GeostoneMarten (arcpy.Exist) but now the point of failure is the verification, not the search cursor.
    – XtianGIS
    Sep 23, 2021 at 7:51

2 Answers 2

2

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".

1
  • 1
    SearchCursor definitely does honor the set workspace because I use it fine on a different computer.
    – geogeogeo
    Jan 14, 2016 at 3:02
0

You can do that. I think it works. I haven't sde connection. I can't test

import arcpy  
from arcpy import env  
env.overwriteOutput = True  

env.workspace ="Database Connections/master.sde"

# check name
fc_list = arcpy.ListFeatureClasses()    

for fcname in fc_list:  
    print fc  

#if wire is named gis.DBO.wire
# use in cursor full name
fcname = "gis.DBO.wire"
fc = os.path.join(env.workspace,fcname)

# check if exist
if arcpy.Exists(fc):
   print "Featureclass Exist"

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.