AnsweredAssumed Answered

Updating the data source of a query layer with ArcPy

Question asked by astjohnrm on Jan 21, 2020

I am using ArcPy to update data sources of all layers across several MXDs using (1) findAndReplaceWorkspacePaths() and (2) replaceDataSource(). 


The workspace path, and dataset name, seem to update fine when I run my script, but the database connection (right-click on layer -> Properties -> Change Query -> Connections... -> Edit... -> Database) does not, and the layer can not find the data to display because it is using the old database connection and not using the newly directed workspace path.


So, I change the workspace path, not see any error, and have the layer metadata (workspace and dataset name = data source) reflect the updates in layer properties, but the database connection isn't actually updating? Is there a property or method that I am missing? Can I do something with the system tables?


I should also note that I can indeed update the database connection and have the data show up in ArcMap, but I have go to each query layer properties (right-click on layer -> Properties -> Change Query -> Connections... -> Edit... -> Database) and update it manually (like outlined here Modifying a query layer—Help | ArcGIS Desktop ), but I need to do this programmatically.


Any insight or recommendations?