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.
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.
We have multiple layers and its not easy to switch connection by using UI. looking for Python script/model builder
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)
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.
Two options:
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.
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?
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.