Monday, 15 January 2018

enterprise geodatabase - Define Workspace for SDE Connection in Python


How do we define SDE Connection for workspace in Python Scripting?



Answer



D.E.Wright just beat me to it, he's right on, use a connection just like in ArcCatalog. But here's my take, done at the Python prompt in ArcMap, using the direct full path to a sde connection file:



>>> import arcpy
>>> arcpy.env.workspace = "C:\\Users\\chad\\AppData\\Roaming\\ESRI\\Desktop10.0\\ArcCatalog\\anrc_water (anrcuser).sde"
>>> fdlist = arcpy.ListDatasets()
>>> for fd in fdlist:
... print fd
...
anrc_water.DBO.ChadTest
anrc_water.DBO.Temp_Data
anrc_water.DBO.Master_Datasets
ANRC_WATER.DBO.ENF_FILL_FACC

ANRC_WATER.DBO.ENF_FILL_FDIR

>>>

To get the path to my sde connection file, I just right-clicked on my SDE database in the Catalog tree, went to properties, then on the General tab, copy the path from the Name field:


enter image description here


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...