This Works
The following python script works when connecting to my dev ArcGIS server, from both the ArcMap python window and the IDLE python GUI/shell running on my dev workstation:
import arcpy
arcpy.env.workspace = "Database Connections/Connection to 172.20.0.XX.sde"
str(arcpy.ListFeatureClasses("*"))
Works: Prints list of all the feature classes in the Enterprise GeoDB
This Does NOT Work
The following python script, which is the same as above but aside from the env.workspace value, DOES NOT work when connecting to my prod ArcGIS server from the IDLE python GUI/shell running on that same ArcGIS server, but DOES work from the ArcMap python window on that server...
When run from ArcMap 10.2.1 python window:
import arcpy
arcpy.env.workspace = "Database Connections/Connection to 172.20.0.XX.sde"
str(arcpy.ListFeatureClasses("*"))
Works: Prints list of all the feature classes in the Enterprise GeoDB
When run from IDLE python GUI/shell:
import arcpy
arcpy.env.workspace = "Database Connections/Connection to 172.20.0.XX.sde"
str(arcpy.ListFeatureClasses("*"))
Fails: Prints 'None'
The Windows user I'm logged into the prod ArcGIS server with is an admin, but The only thing I can come up with is
Notes
Note I have tried all of the following variations when setting the workspace:
- arcpy.env.workspace = r"Database Connections\Connection to 172.20.0.49.sde"
- arcpy.env.workspace = "Database Connections\Connection to 172.20.0.49.sde"
- arcpy.env.workspace = "Database Connections" + os.sep + "Connection to 172.20.0.49.sde"
- arcpy.env.workspace = os.path.join("Database Connections", "Connection to 172.20.0.49.sde")
- Etc...
-
2Is the password saved in the .SDE file or do you get a login dialog in ArcMap?Jason Scheirer– Jason Scheirer2014年10月22日 22:17:22 +00:00Commented Oct 22, 2014 at 22:17
-
I think this is similar to gis.stackexchange.com/questions/5540/…PolyGeo– PolyGeo ♦2014年10月22日 22:22:09 +00:00Commented Oct 22, 2014 at 22:22
-
Just test if the workspace is found, like : arcpy.Exists(arcpy.env.workspace).Neil Ayres– Neil Ayres2014年10月23日 05:44:50 +00:00Commented Oct 23, 2014 at 5:44
-
> Jason, no login dialog in ArcMap. > PolyGeo, yes, step 2 of blah238's post was the solution... full path. > Neil, I had tried that, it was not finding the workspace. I would like to understand why this was happening: the IDLE python shell can't resolve or access the same relative path that the ArcMap python window can...FlashJordan– FlashJordan2014年10月23日 16:14:46 +00:00Commented Oct 23, 2014 at 16:14
1 Answer 1
The answer which I found yesterday, and PolyGeo referenced in his comment above, was to use the full path to the sde instead of the relative path. I still don't understand why the IDLE GUI/shell can't use the relative path when the ArcMap python window can.
Explore related questions
See similar questions with these tags.