5

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
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Nov 29, 2015 at 1:30
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? Commented 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"? Commented 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. Commented Sep 23, 2021 at 7:51

2 Answers 2

1

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

answered Nov 30, 2015 at 15:33
1
  • 1
    SearchCursor definitely does honor the set workspace because I use it fine on a different computer. Commented 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]
answered Nov 30, 2015 at 16:12

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.