rmcculley

arcpy and SDE outside of ArcGIS

Discussion created by rmcculley on Oct 16, 2013
Latest reply on Jun 3, 2016 by rgregory1963
I'm having trouble accessing ArcSDE Feature Classes from Python running outside of ArcGIS 10.2.

I put together a quick test script:

import arcpy

# Test for existence of various datasets, both in SDE and shapefile
for pth in (r"Database Connections\GIS.sde",
               r"C:\Users\RMcCulley\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\GIS.sde",
               r"Database Connections\GIS.sde\gis.cvr.Basemap\gis.cvr.Townships",
               r"G:\Parcel GIS Files\Townships.shp"):
    if arcpy.Exists(pth):
        value = pth + " Exists"
    else:
        value = pth + " Doesn't Exist"
    arcpy.AddMessage(value)

# Try FeatureClassToFeatureClass to export from Shapefile to Shapefile
if arcpy.Exists(r"C:\Temp\Townships_From_SHP.shp"): 
    arcpy.Delete_management(r"C:\Temp\Townships_From_SHP.shp")
try:
    value = arcpy.FeatureClassToFeatureClass_conversion(in_features=r"G:\Parcel GIS Files\Townships.shp",out_path=r"C:\Temp",out_name="Townships_From_SHP.shp")
except:
    value = "FeatureClassToFeatureClass Failed"
arcpy.AddMessage(value)

# Try FeatureClassToFeatureClass to export from SDE to Shapefile
if arcpy.Exists(r"C:\Temp\Townships_From_SDE.shp"): 
    arcpy.Delete_management(r"C:\Temp\Townships_From_SDE.shp")
try:
    value = arcpy.FeatureClassToFeatureClass_conversion(in_features=r"Database Connections\GIS.sde\gis.cvr.Basemap\gis.cvr.Townships",out_path=r"C:\Temp",out_name="Townships_From_SDE.shp")
except:
    value = "FeatureClassToFeatureClass Failed"
arcpy.AddMessage(value)


If I run this from Toolbox inside of ArcGIS the output is:
Executing: arcpytesting
Start Time: Wed Oct 16 13:12:03 2013
Running script arcpytesting...
Database Connections\GIS.sde Exists
C:\Users\RMcCulley\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\GIS.sde Exists
Database Connections\GIS.sde\gis.cvr.Basemap\gis.cvr.Townships Exists
G:\Parcel GIS Files\Townships.shp Exists
C:\Temp\Townships_From_SHP.shp
C:\Temp\Townships_From_SDE.shp
Completed script arcpytesting...
Succeeded at Wed Oct 16 13:12:04 2013 (Elapsed Time: 1.00 seconds)


Everything works fine!

If I run this at the command line using C:\Python27\python.exe arcpytesting.py the output is:
Database Connections\GIS.sde Exists
C:\Users\RMcCulley\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\GIS.sde Exists
Database Connections\GIS.sde\gis.cvr.Basemap\gis.cvr.Townships Doesn't Exist
G:\Parcel GIS Files\Townships.shp Exists
C:\Temp\Townships_From_SHP.shp
FeatureClassToFeatureClass Failed


The feature class inside the SDE database doesn't exist, and the FeatureClassToFeatureClass from the SDE database fails.

The exception is:
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Features: Dataset Database Connections\GIS.sde\gis.cvr.Basemap\gis.cvr.Townships does not exist or is not supported
Failed to execute (FeatureClassToFeatureClass).


Is there something I'm missing? Should this script work outside of ArcGIS?  It seems strange that arcpy outside of ArcGIS works fine on shapefiles or file geodatabases (I tested this as well), but not on SDE datasets.

Outcomes