27

I have an MXD. It connects to about 30 layers in one of our SDE databases. I want to change the SDE database they connect to.

Is there a way to do this without having to right-click every layer and change it individually?

6 Answers 6

39

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:

1
  • This seems to not work in 10.1. The data source is changed, but (at least in the case of an SDE connection) the link is changed to a "database connection", i.e. the layer isn't being pointed to any longer, which breaks the link. Sep 6, 2012 at 15:28
18

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.

2
  • This works perfectly thanks! One thing to add is "Database Connections\Connection to GISSDE1.sde" can be replaced with a .gdb location too. Jan 4, 2017 at 19:41
  • How would I be able to use this from switching the data source from the SAME SDE but from version 1 to version 2?
    – NULL.Dude
    Apr 6, 2017 at 12:32
3
  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.

2
  • Its very helpfull.Please go throug this once Dec 20, 2012 at 6:13
  • 5
    This will only work if the connections are broken, otherwise one of the other answers are more appropriate.
    – blah238
    Dec 20, 2012 at 6:29
1

http://arcscripts.esri.com/details.asp?dbid=14922

The link is to an old Arcscript called GDK tools, wich can be obtained on other sites. The Program creates a toolbar in arcmap where you can change source on selected layers (any layer you want. this works between SDE connections or SDE to local file geodatabase (wich change source in Arccatalog not can handle, because of the name in SDE starts with the SDE user and then dot.

this is very helpful, but maybe only in arcgis 9.3

2
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes.
    – BradHards
    Feb 14, 2014 at 10:01
  • I Have modified!
    – jonaktiv
    Feb 14, 2014 at 12:57
1

If you've got the .mxd open already, do what @blah238 did, but use 'CURRENT' instead of the full path. Don't forget that the search and replace doesn't have to be the full string:

import arcpy
mxd = arcpy.mapping.MapDocument('CURRENT')
mxd.findAndReplaceWorkspacePaths(r"scratch", 
                                r"project/draft")

Then you'll have to save and reopen the .mxd file anyway.

1

For one mxd, default ESRI tools can suffice. But fixing multiple mxds with broken links can be a nightmare. Try my UpdateLayerRefs tool to fix unlimited MXDs in seconds: https://github.com/jswagger/UpdateLayerRefs Just provide the names of your input MXD's as a list ["Name1.mxd", "Name2.mxd", "Name3.mxd"]

7
  • Nice sharing your code :) Can you elaborate a bit on how one can use it ?
    – gisnside
    Aug 28, 2017 at 17:27
  • Absolutely: 1. Fill out JSON config file: Aug 29, 2017 at 20:46
  • First step, i guessed ! But i'm wondering about after - Seems your comment didn't hit the ground for the rest of the message. You should maybe edit your answer instead :) :)
    – gisnside
    Aug 29, 2017 at 20:53
  • 1
    Sorry, got pulled off on something. Updating the readme file now.... Aug 29, 2017 at 21:06
  • 1
    That is correct. Running python UpdateLayerRefs.py --config "update_layer_refs.config.json" allows you to run it in any folder. Aug 29, 2017 at 21:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.