Changing data source for all layers in MXD?

Right click on the mxd in ArcCatalog, click on Set data sources, and bulk change from there. However, this tool warns:

Note: this dialog is intended primarily for preparing map documents for publication. Customizations (VBA code, UI Controls and custom toolbars), graphs, and table window appearance properties are removed from .mxd files when you update their data sources using this dialog. To preserve these, update the data sources in ArcMap instead.

You could also use the arcpy.mapping python library:


If you are using ArcGIS 10 and are interested in using Python, check out the help on Updating and fixing data sources with arcpy.mapping and the methods of the Layer object.

Example:

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project_SDE1.mxd")
mxd.findAndReplaceWorkspacePaths(r"Database Connections\Connection to GISSDE1.sde", 
                                r"Database Connections\Connection to GISSDE2.sde")
mxd.saveACopy(r"C:\Project\Project_SDE2.mxd")
del mxd

If your layers don't all source the same original connection file, or the destination feature class name is different on the new SDE, you might need to use Layer.replaceDataSource instead.


  1. Make a data source connection in ArcCatalog.
  2. Open the MXD and expand the layer and click on the red exclamation mark in any layer. This will open a popup window containing the data source with database connection.
  3. Select the database connection that you had made, double-click on that and go inside that to the layer that you have clicked and select that layer and press OK, Open or Add.

This will remove all the red exclamation mark containing layers in the MXD and will point to the new created data source. In one go you can do this; no need to go and click each time on the red exclamation mark and clicking and setting the data source.