Connect to SDE with arcpy

23531
2
08-13-2010 11:40 AM
ChrisMathers
Occasional Contributor III
All I can find in the help for connecting to an SDE with arcpy is how to make a SDE connection file. I already have one of those because the SDE is available in catalog (C:\Documents and Settings\cmathers\Application Data\ESRI\ArcCatalog\OSA@sde@bay-gis.sde). I just want to know how to read that file with arcpy and then read some data from the server. How do I connect to the SDE from python?
0 Kudos
2 Replies
AndrewChapkowski
Esri Regular Contributor
To list data from the server, you can do something like this:

import arcpy
from arcpy import env
env.overwriteOutput = True
env.workspace = r"C:\Documents and Settings\cmathers\Application Data\ESRI\ArcCatalog\OSA@sde@bay-gis.sde"
fcList = arcpy.ListFeatureClasses()

# Copy shapefiles to a file geodatabase
#
for fc in fcList:
    print fc




That's just one example of how you can use sde connection files. 

If you wanted to reference a feature class, you could do something like this:
fc = r"C:\Documents and Settings\cmathers\Application Data\ESRI\ArcCatalog\OSA@sde@bay-gis.sde\<FeatureClassName>"


Hope this helps.
ChrisMathers
Occasional Contributor III
Thanks a lot. Using the sde file as the workspace is just what I needed to know!
0 Kudos