I am trying to list featureclasses in an enterprise GDB via SDE database using the code below. If I run this from within ArcMap/Catalog it works fine - prints out all the featureclass names. If I run this from within pyscripter OR by double clicking the .py it returns fcList as an empty list. Would anyone have any idea why this fails in the stand alone script? It is as if the connection to the SDE is not opened?
I have googled this but am unable to find a solution (this question seems to outline a similar issue arcgis 10.2 - arcpy.ListFeatureClasses returns empty list - Geographic Information Systems Stack Exc... ). I have tried setting the path to the .sde using <database connections> and also by fully qualifying the path but it makes no difference.
Oracle database is using operating system authentication. Currently attempted this on ArcGIS 10.7.1 and 10.6.1 - both do not work. Windows 10 - our IT department have locked it down so we cannot run as administrator - perhaps this is causing the issue?
Happy to provide further information on anything if it can help and any help greatly appreciated!
import arcpy from arcpy import env import os # Establish connection for workspace env.workspace = r"<path to sde conn file.sde>" print(os.path.exists(env.workspace)) #Returns True #call ListFeatureClass function fcList = arcpy.ListFeatureClasses() print(len(fcList)) #Returns 0 # Print the name of the current fc: for fc in fcList: print(fc)
Thanks for the reply. I adjusted the code from the Walk example #1 as below. Same old story, unfortunately, it returns a populated list from within ArcMap/Catalog and an empty list from a stand-alone script.
import os workspace = r"<path-to-db-conn.sde" feature_classes =  walk = arcpy.da.Walk(workspace, followlinks=True, datatype="FeatureClass", type="Polygon") for dirpath, dirnames, filenames in walk: for filename in filenames: feature_classes.append(os.path.join(dirpath, filename)) print(len(feature_classes))
I've been watching this thread. Something simple like this doesn't work for you from a python console?
import arcpy arcpy.env.workspace = r'\\filesytem\path\to\connection.sde' for fc in arcpy.ListFeatureClasses(): print(fc)
It's all I ever use...
Thanks for the reply. Unfortunately no - I am sure I have used almost this exact code successfully in the past but it doesn't work for me now. I just tried with your code substituting my connection file path and it returns no results.
I am leaning toward this issue being caused by a combination of factors related to how our agencies network and enterprise GDB are configured as this seems to be a simple task for most everyone else.
You might want to have a talk with your security team and/or network team; your user credentials are okay when you run the command from the client (ArcMap/Catalog) but not for your user that runs the script, yet others don't seem to have an issue. Seems odd, but it's worth a visit.