Update SDE Connection Properties in ArcGIS Pro Project Via ArcPy

8210
12
Jump to solution
06-04-2019 12:20 PM
Clint_Glover
New Contributor III

Currently within my organization, password rules have been put in place that requires us to update our Oracle passwords every 90 days.  Due to these rules, I am in the process of creating a python script for both ArcMap mxds and ArcGIS Pro projects.  We currently have our SDE connection files in a shared directory to make this process easier.  When a password change is required, we update the Oracle password and then update the password for the associated SDE connection file in the shared directory.  Our intentions are to reuse the SDE connection files after a password changes, so our python scripts essentially should just reset each layer's connection info back to itself, which would then contain the updated password for the associated SDE file.

The ArcMap python script has been created and works correctly using the .replaceDataSource function.  When I began working on the ArcGIS Pro python script, I ran into issues using the updateConnectionProperties function for layers within a map in a ArcGIS Pro project that used SDE connection files in our shared directory.  I attempted to set the new SDE connection file for each layer back to itself (which works with the replaceDataSource function for ArcMap), due to the SDE connection file staying the same, with only the password being updated.  I have also attempted to reset each layer's connection properties to a completely new SDE file, but that doesn't appear to work either.  None of ESRI's examples show using updateConnectionProperties to go from one SDE connection to another SDE connection file.  Does anyone know if this is possible or if there is an alternate route I can take to complete this task?  For reference, I am using the latest version of ArcGIS Pro (2.3.3) and our SDE connection files are pointed to an Oracle database (12c).

12 Replies
Arne_Gelfert
Occasional Contributor III

Hey Clint, thanks for posting. I had virtually the same issue and started this thread a while back. In the end, I settled for your approach as well. That's so ESRI though! Instead of letting you replace one reference to an SDE file with a reference to another SDE file, they tell you to hardcode a password into the script.

I guess you could just prompt for a password during execution. Somewhere I also have a snipped for reading in a password without showing it. Could be that it only works with arcgis module though. - Thanks again.

Clint_Glover
New Contributor III

Yes I totally agree.  Nothing ever seems straightforward with ESRI.  I'm not sure how we are going to handle it yet (not really using ArcGIS Pro just yet for publishing our web services), but we will come up with something in the near future.

0 Kudos
diaconori
New Contributor III

What's the accepted answer to this? Clint's answer is marked as the accepted answer yet he clearly states that it does not solve the problem.

EDIT:

I tried to change the SDE connection in ArcMap using Python 2.7 and the following function:

lyr.findAndReplaceWorkspacePath(old_path, new_path, True)

It works. You guys may want to consider using the ArcMap route even though it seems counter intuitive...

0 Kudos