How to Set Data Source of a Layer In an MXD From SDE connection

Discussion created by behClevest on Aug 28, 2017
Latest reply on Aug 29, 2017 by behClevest

Can you please take a look at this example and let me know how to I can replace Data Source data of a layer in a saved mxd map (Fuse) to a layer called SDEElectric.DBO.Fuse which is in an enterprise geodatabase through database connection


I tried this code but it didnt work

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\GIS\Maps\Electric.mxd")
src =r"C:\Users\xxx\AppData\Roaming\ESRI\Desktop10.4\ArcCatalog\SDEElectric.sde\SDEElectric.DBO.Dataset\SDEElectric.DBO.Fuse"
df = arcpy.mapping.ListDataFrames(mxd, "")[0]
for lyr in arcpy.mapping.ListLayers(mxd, "", df):
if == "Fuse":
lyr.replaceDataSource(src, "FILEGDB_WORKSPACE", "")
del mxd
print "done"