Hello,
Following this guide, https://pro.arcgis.com/en/pro-app/3.3/arcpy/mapping/updatingandfixingdatasources.htm
Trying to update the connection properties of multiple files. The new way works for the majority of the datasets (including FCs, Raster, FC with joins in them) except when it has tables. This works fine from one gdb to another gdb but it breaks for TABLES when gdb to sde.
aprx = arcpy.mp.ArcGISProject(r'some_aprx_path')
aprx.updateConnectionProperties(
local_gdb_path, # local gdb file where data currently reside
Tables require explicit connection properties rather than just the connection file path and tables don't connection information the same way as feature layers do.
untested
# Configuration
old_gdb_path = r"C:\Temp\database.gdb"
sde_connection_file = r"C:\Temp\connection.sde"
# Hardcoded SDE connection properties
sde_props = {
"authentication_mode": "dbms",
"database": "your_database_name", # e.g. "sde" for SQL Server
"dbclient": "sql", # or "oracle", "postgresql" depending on your DBMS
"db_connection_properties": "your_server_name",
"instance": "sde:sqlserver:your_instance", # adjust for your DBMS
"server": "your_server_name",
"user": "your_username",
"version": "SDE.DEFAULT",
"password": "your_password" # Consider secure storage methods
}
# Load project
aprx = arcpy.mp.ArcGISProject("CURRENT") # or specify path to .aprx
# Process all items
for m in aprx.listMaps():
print(f"Processing map: {m.name}")
# Process layers
for lyr in m.listLayers():
if lyr.supports("DATASOURCE"):
old_conn = lyr.connectionProperties
if old_conn.get('database', '').lower() == old_gdb_path.lower():
print(f" Updating layer: {lyr.name}")
lyr.updateConnectionProperties(old_conn, {"database": sde_connection_file})
# Process tables
for table in m.listTables():
old_conn = table.connectionProperties
if old_conn.get('database', '').lower() == old_gdb_path.lower():
print(f" Updating table: {table.name}")
table.updateConnectionProperties(old_conn, sde_props)