I would like to update the connection property in all .msd in a folder, that already have a certain connection property.
The manual process is to

  • right click on the .msd,
  • select "select all",
  • select "replace all",
  • select the layer in the local SDE fot that map,
  • click add
  • and ok.

Can I do this with ArcPy?

PS. The reason for doing this is the password changed in the .sde and this is an alternative to republishing the service.

enter image description here


A msd file references a mxd file. So you should fix the datasource of mxd. I reccommend to check this web page of documentation and use findAndReplaceWorkspacePath for this purpose.

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project_default.mxd")
mxd.findAndReplaceWorkspacePaths(r"C:\Project\Connection to Default.sde", 
                                 r"C:\Project\Connection to Version1.sde")
del mxd


Starting at ArcGIS 10.1 for Server, Map Server Definition (.msd) files have been replaced with Service Definition Draft (.sddraft) and Service Definition (.sd) files.

Since Service Definition Draft (.sddraft), Service Definition (.sd) and msd files are xml file, you should parse the xml and extract the mxd from the xml.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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