jskinner-esristaff

Change MXD data sources to another SDE geodatabase

Discussion created by jskinner-esristaff Employee on Jul 18, 2011
Latest reply on Apr 11, 2017 by jskinner-esristaff
Is it possible to change the data source of an MXD to another SDE geodatabase?  I've tried this, but have only been able to get this to work when switching versions within the same SDE geodatabase.  Ex:

import arcpy
from arcpy import env
env.workspace = workspace = r"C:\temp\python"

env.overwriteOutput = True

mxdList = arcpy.ListFiles("*.mxd")

for mxd in mxdList:
    mxd2 = workspace + "\\" + mxd
    mapdoc = arcpy.mapping.MapDocument(mxd2)
    mapdoc.findAndReplaceWorkspacePaths(r"C:\TEMP\Python\VECTOR_Default.sde", r"C:\TEMP\Python\VECTOR_QAQC.sde")
    mapdoc.save()

del mapdoc


The above code works as I am switching from one version (SDE.Default) to another version (SDE.QAQC) within the same VECTOR geodatabase.  When I try to switch to another SDE geodatabase that contains the same feature class (same owner and feature class name, just different database), it does not work.  Ex:

import arcpy
from arcpy import env
env.workspace = workspace = r"C:\temp\python"

env.overwriteOutput = True

mxdList = arcpy.ListFiles("*.mxd")

for mxd in mxdList:
    mxd2 = workspace + "\\" + mxd
    mapdoc = arcpy.mapping.MapDocument(mxd2)
    mapdoc.findAndReplaceWorkspacePaths(r"C:\TEMP\Python\VECTOR_Default.sde", r"C:\TEMP\Python\RASTER_Default.sde")
    mapdoc.save()

del mapdoc


Thanks for any suggestions!

Outcomes