Hi guys,
I want to get list of my database connections (see pic.) in Arcpy to display them in my tool dropdown list, i try next code:
workspaces = arcpy.ListWorkspaces("*", "SDE")
for workspace in workspaces:
print workspace
but it does not give any result. How can i do that?
Thank you
ListWorkspaces—ArcGIS Pro | Documentation
what did the print statement produce?
where in your code did you set your workspace to start the search?
The workspace environment must be set before using several of the list functions, including ListDatasets, ListFeatureClasses, ListFiles, ListRasters, ListTables, and ListWorkspaces.
Hi Dan,
1) Question: what did the print statement produce?
Answer: Print statement should produce list of database connections i have in TOC. (See pic. please)
2) Question: where in your code did you set your workspace to start the search?
Answer: I set workspace at the beginning of my code, after Import arcpy and import os.
I might on wrong way and try to achieve wrong result, but i thought this is a right way :(.
You will need to post the code that show that and the actual workspace so one can assess whether your database connections are associated with it
Hello, for me all me SDE connections are in the same folder (workspace) so if you define the workspace, you should get your listing of SDE databases. Worked for me. 🙂 (in Catalog, right click the SDE connection, select properties and look at the path of the "name")
import arcpy
arcpy.env.workspace = r"C:\Users\USERNAME\AppData\Roaming\ESRI\Desktop10.8\ArcCatalog"
# List all file geodatabases in the current workspace
workspaces = arcpy.ListWorkspaces("*", "SDE")
for workspace in workspaces:
print workspace
If I was looking for a list of SDE connection in the workspace I would do it this way
import arcpy, os
ROOT_DIR = os.path.dirname(arcpy.env.workspace)
for file in os.listdir(ROOT_DIR):
if file.endswith(".SDE"):
print(file)