I am trying to update the connection properties of a group layer onto a new geodatabase, and even though the script runs, the data sources end up being broken. I was wondering what I can do to fix this?
I've been wrestling with that method call all week. I think passing a dictionary in to it is getting me closer. I will try to post some actual code here later. Basically I read the existing properties, modify, then write back out.
I iterate over all the maps in an APRX, then iterate over the layers in each map. Then read properties for each layer, modify, write to map, then save the APRX.
It's not perfect yet but it's getting better.
properties = None
try:
properties = lyr.connectionProperties
except Exception as e:
messages.addMessage(f" no connectionProperties ?? {e}")
continue
Now I have properties, I can change them, for example,
properties['connection_info']['server'] = server
properties['connection_info']['instance'] = f"sde:sqlserver:{server};MULTISUBNETFAILOVER=YES"
lyr.updateConnectionProperties(None, # Careful! This replaces ANYTHING
properties,
auto_update_joins_and_relates = True)
Lots of code right now surrounds these blocks, dumping out messages
and testing for layer types to be ignored... not showing any of that here.