Select to view content in your preferred language

ArcGIS Pro Change connections from one SDE to another

545
7
12-18-2024 05:43 AM
sahook1
Occasional Contributor

I have a project, and I wanted to change the deployment from DEV environment to TEST. While deploying in test environment I need to change the data source from DEV database to TEST for all layers.

The connections are made to DEV and TEST SDE ( DBMS Authentication ) and wanted to change the connection by using a simple script.

I am aware of the script uses find and replace the connection info but I am looking for something without the user id and password.

0 Kudos
7 Replies
MichaelVolz
Esteemed Contributor

Does the Data Sources Update tool from the Catalog ribbon not provide the functionality to perform this task?

It works like the Set Data Sources tool in ArcCatalog when you select an mxd file.

0 Kudos
sahook1
Occasional Contributor

We have multiple layers and its not easy to switch connection by using UI. looking for Python script/model builder

0 Kudos
AlfredBaldenweck
MVP Regular Contributor

Try layer or map or aprx.updateConnectionProperties().

If you feed it an SDE file with credential saved, you won't have to worry about entering the password.

gdb1 = r"...\gdb1.sde"
gdb2 = r"...\gdb2.sde"
#Coarse control
aprx = arcpy.mp.ArcGISProject("CURRENT")
aprx.updateConnectionProperties(gdb1, gdb2)
#OR
#Finer control
mp = aprx.activeMap
mp.updateConnectionProperties(gdb1, gdb2)
# OR
#Finest control
for lay in mp.listLayers():
    # Don't worry about whether it's a group layer or not for this.
    lay.updateConnectionProperties(gdb1, gdb2)

 

0 Kudos
sahook1
Occasional Contributor

Hi AlfredBaldenweck,

I did tested this script yesterday but the real challenge is saving connection files in a certain location to achieve it.
there are multiple user involved in this deployment process and everyone doesn't save the connection file in same path. any script to avoid this ?

as the APRX is connected to DEV and TEST, I am assuming it we should be able to run a script to change connection without using additional connection path in the script.

Preview
 
 
 
0 Kudos
AlfredBaldenweck
MVP Regular Contributor

Two options:

  1. Hard-code in the path to your script.
    1. If you are constantly doing the same switch, it doesn't really matter which particular SDE files you use so long as the user has access to see them when the script runs. 
  2. Make a script tool and each sde file your parameter.
    1. (See attached ATBX; I made the parameters and popped in the script)

I'd also considering standardizing your connections, if you can. Make everyone save with the same name in the same general place (User\Documents\ArcGIS\ConnectionFiles, for example), or better yet, have everyone go to the same file in a shared location if that's possible.

 

0 Kudos
sahook1
Occasional Contributor

Thanks for your feedback,
Is it safe to save the connection file in a certain location and access by all the users?

What is the encryption method used to  save the file in local?

0 Kudos
AlfredBaldenweck
MVP Regular Contributor

Honestly, that's outside of my expertise. Check out this page for more details: Connections to relational databases in ArcGIS Pro—ArcGIS Pro | Documentation

In the meantime, using a script tool that allows the user to choose which connection files to use will definitely get the job done.

0 Kudos