AnsweredAssumed Answered

ReplaceDataSource of SDE layers in map documents (mxd)  with old feature classes newly organized under feature datasets in the same ArcSDE

Question asked by kkumbadaesri on Jul 18, 2016
Latest reply on Feb 24, 2017 by yguan13

Hello all,


I need some help to replace the data source of old SDE layers
in the map documents. The code outlined below is not working properly resulting
result in a broken link.


We recently reorganized our ArcSDE database resulting in all
previous feature classes reorganized under the feature dataset with a new name.
In the interim, the SDE has both old and new data.  That results in a lot of map documents, in
which the data sources of all the layers need to be replaced with new workspace
path. Eventually, we want to delete the old SDE feature classes directly under the


Based on our research, lyr.replaceDataSource seems a
plausible solution since it provides an option of replacing both work space
path and dataset name.


I greatly appreciate any input.


Thank you,




#loop through the folder to locate mxds and layers within it and replace data source
of SDE layer

for fileName in os.listdir(path):

    fullPath = os.path.join(path,

if os.path.isfile(fullPath):

        basename, extension =

if extension == ".mxd":

            mxd =

print "MXD: " + fileName


            #get the list of all the layers

brknList = arcpy.mapping.ListLayers(mxd)

# Remove temporary connection file if it already exists

sdeFile = r"C:\Project\Output\TempConnection.sde"


print sdeFile


#replace data source of individual SDE layer

for brknItem in brknList:

if brknItem.datasetName == 'GISADMIN.ABC_Stations':

"SDE_WORKSPACE",newStation, False)

              #elif brknItem.datasetName == 'GISADMIN.ABC_Layer':

              #     brknItem.replaceDataSource(wrkspcInfra2, "SDE_WORKSPACE",newABCLayer, False)



outmxd = basename + "_3"+ extension