HOW TO

Update the data source between Enterprise geodatabases in ArcGIS Pro using ArcPy

Last Published: July 6, 2020

Summary

When trying to update the data source for all layers in an ArcGIS Pro project, it is necessary to manually update each layer if the data source is not broken. To simplify this, the ArcPy updateConnectionProperties function can be used to programmatically update all layers in a project.

There is a bug with the updateConnectionProperties function when attempting to update the data source from one Enterprise geodatabase to another. The code executes without error message, but no properties are updated. The connectionProperties dictionary must be used for the parameters.

Procedure

Using the connectionProperties dictionary to update the data source from one Enterprise geodatabase to another:

import arcpy

aprx = arcpy.mp.ArcGISProject(r'C:\Projects\project.aprx')

find_dict = {'connection_info': {'authentication_mode': 'DBMS',           
           'database': 'Giza',           
           'db_connection_properties': 'Egypt',           
           'dbclient': 'sqlserver',           
           'instance': 'sde:sqlserver:Egypt',           
           'password': 'hermitPurple123',           
           'server': 'Egypt',           
           'user': 'Romeo',           
           'version': 'sde.DEFAULT'}, 
'workspace_factory': 'SDE'}}

replace_dict = {'connection_info': {'authentication_mode': 'DBMS',      
      'database': 'Khufu',      
      'db_connection_properties': 'Egypt',      
      'dbclient': 'sqlserver',      
      'instance': 'sde:sqlserver:Egypt',      
      'password': 'theWorld123',      
      'server': 'Egypt',      
      'user': 'Maya',      
      'version': 'sde.DEFAULT'}, 
'workspace_factory': 'SDE'}}

aprx.updateConnectionProperties(find_dict, replace_dict)

Replace the find_dict connection info with the source database connection, and the replace_dict connection info with the target database connection. If this information is unknown, run the following script:

Print the connection_info to find the information about a database connection

import arcpy, pprint
p = arcpy.mp.ArcGISProject('current')
m = p.listMaps()[0]
l = m.listLayers()[0]
pprint.pprint(l.connectionProperties)

Returns connection property information in this format:

{'connection_info': {'authentication_mode': 'DBMS',           
           'database': 'Khufu',           
           'db_connection_properties': 'Egypt',           
           'dbclient': 'sqlserver',           
           'instance': 'sde:sqlserver:Egypt',           
           'password': '*********',           
           'server': 'Egypt',           
           'user': 'Romeo',           
           'version': 'sde.DEFAULT'}, 
'dataset': 'Egypt.SDE.Centerlines', 
'workspace_factory': 'SDE'}
Note:
The password will be returned as a string of asterisks (****). The user must type their password as plain text in the parameters as shown in the example, if using database authentication.

If the listLayers function returns an indexing error, the project may contain layers that are missing or broken.

Article ID:000021728

Software:
  • ArcGIS Pro

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic