Select to view content in your preferred language

Update Properties not working

484
1
09-08-2023 10:48 AM
AnjeliDubey
Emerging Contributor

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?

for lyr in group_layer:
            try:
                if lyr.supports("CONNECTIONPROPERTIES"😞
                     
#Update properties function
                    lyr.updateConnectionProperties("", curr_gdb)
 
This is what the data source is supposed to look like for the layer:
Update Properties.png
 
However, even though it successfully updates connective properties to the certain geodatabase I want, this is what the data source looks like for the layer when I run the code:
Update Properties Error.png
0 Kudos
1 Reply
Brian_Wilson
Honored Contributor

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.
0 Kudos