ArcSDE Layer Management – Permanently Replace/Update Server/Service in Each Layer in MXD

arcgis-10.0arcpyenterprise-geodatabase

Using the mxd.findAndReplaceWorkspacePaths method, if and MXD is updated and the path the the .sde connection file moves again all of the data sources will break again.

Is there a method to permanently update each SDE layer in an MXD Table of Contents to permanently store the SDE Server and Service? Ie. Just replace the SERVER and INSTANCE for each SDE layer in an MXD using python or ArcObjects in Pyhton?

Best Answer

I have found a solution to breaking the dependence on path to the .sde connection file using ArcPy and the following method.

This way works:

lyr.replaceDataSource(sdeConn, "SDE_WORKSPACE", lyr.datasetName, False)
table.replaceDataSource(sdeConn, "SDE_WORKSPACE", lyr.datasetName, False)

You can rename or delete the connection file after the MXD has been repaired and saved. It will continue to open without issue after the connection file is no longer there.

These methods DO NOT work:

mxd.findAndReplaceWorkspacePaths
lyr.findAndReplaceWorkspacePath

You CANNOT rename or delete the connection file after the MXD has been repaired. The MXD will look for the .sde connection file in the same location always each time it's opened.

Related Question