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?
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.
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