Last active
June 29, 2017 19:53
-
-
Save bixb0012/c8bf3eea26977dd22e2b678bf36792d8 to your computer and use it in GitHub Desktop.
ArcPy (ArcMap): Get List of Geodatabases in Database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Adapted from http://stackoverflow.com/questions/18141547/display-all-the-names-of-databases-containing-particular-table | |
# | |
# Reference: 1) http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/create-database-connection.htm | |
# 2) http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-classes/arcsdesqlexecute.htm | |
import arcpy | |
conn_path = # Output folder for database connection file | |
conn_name = # Output name of database connection file, including .sde extension | |
# Example 1: SQL Server | |
inst = # SQL Server instance | |
sql = ("SELECT name " | |
"FROM sys.databases " | |
"WHERE CASE " | |
"WHEN state_desc = 'ONLINE' THEN " | |
"OBJECT_ID(QUOTENAME(name) + '..[SDE_Version]', 'U') " | |
"END IS NOT NULL") | |
conn_file = arcpy.CreateDatabaseConnection_management(conn_path, | |
conn_name, | |
"SQL_SERVER", | |
inst, | |
"OPERATING_SYSTEM_AUTH") | |
sde_conn = arcpy.ArcSDESQLExecute(conn_file) | |
sde_res = sde_conn.execute(sql) | |
print sde_res | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment