Setting the workspace to SDE

Discussion created by jdrvar on Apr 18, 2014
My script works as intended when the workspace and variables are set to a File Geodatabase, but not when connecting to SDE.    The commented out lines show how the script runs when connecting to a File Geodatabase vs. my SDE setup. 

The end result is a csv file.  Using the SDE setup calls the sub layer and outputs the correct results, but does not write out par layer results.

import arcpy
import getpass

#arcpy.env.workspace = "H:\\Python\\Python.gdb" #File Geodatabase
arcpy.env.workspace = "Database Connections\\Connection_to_sde2.sde" #SDE

mxd = arcpy.mapping.MapDocument ("CURRENT")
df = arcpy.mapping.ListDataFrames (mxd)[0] 
#sub = arcpy.mapping.ListLayers(mxd, "Subdivisions", df)[0] #File Geodatabase
#par = arcpy.mapping.ListLayers(mxd, "Parcels", df)[0] #File Geodatabase
sub = arcpy.mapping.ListLayers(mxd, "LIBRARIAN.Subdivisions", df)[0] #SDE
par = arcpy.mapping.ListLayers(mxd, "LIBRARIAN.Parcels", df)[0] #SDE