<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic MXD-file corrupt after changing the embedded SDE-Connection in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/mxd-file-corrupt-after-changing-the-embedded-sde/m-p/553895#M43266</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am facing the folling problem: We have a bunch of MXD files which contain some layers that reference a SDE as datasource.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;We are about to change our SDE-server. The new server is already running and contains the nessecary data.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As we don't want to change each MXD individually I created some bash and python scripts that should do the job for us.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am using the function "findAndReplaceWorkspacePaths" to switch the .sde connection files.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;As I want to keep the original file I use "saveACopy" to create a new MXD-file with the new connection.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;However the new MXD-file seems corrupt since I can't open it with any ArcGIS Desktop tools (ArcMap, ArcCatalog MapPathEditor) yet I can publish the MXD as a Service on our ArcGIS Server 10.0&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Basically I use the following two Scripts to change a MXD:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Create the new SDE-connection file:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
import arcpy
folderName = "/arcgisserver/geoserv/test"
fileName = "Connection_to_new_server.sde"
serverName = "SERVER-IP"
serviceName = "5151"
databaseName = ""
authType = "DATABASE_AUTH"
username = "user"
password = "pass"
saveUserInfo = "SAVE_USERNAME"
versionName = "SDE.DEFAULT"
saveVersionInfo = "SAVE_VERSION"
arcpy.CreateArcSDEConnectionFile_management (folderName, fileName, serverName, serviceName, databaseName, authType, username, password, saveUserInfo, versionName, saveVersionInfo)
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Changing the MXD:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
import arcpy 
mapdoc_in = "/source/path/source.mxd"
mapdoc_out = "/target/path/target.mxd"
sde_src = "/home/user/Connection_to_old_server.sde"
sde_target = "/home/user/Connection_to_new_server.sde"
mxd = arcpy.mapping.MapDocument(mapdoc_in)
mxd.findAndReplaceWorkspacePaths(sde_src, sde_target)
mxd.saveACopy(mapdoc_out)
del(mxd)
exit()
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When running the scripts no errors are promted.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Could it be an encoding related problem? (different encoding on the server running the script and the user's PC that created the original MXD)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;regards&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-Florian&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ps: If I check the workspace paths of all the layers of the newly created MXD they all point correctly to the new server&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt; 
[...]
MXD = arcpy.mapping.MapDocument(fullpath)
for lyr in arcpy.mapping.ListLayers(MXD):
if lyr.supports("workspacePath"):
source = lyr.workspacePath
print "%s -&amp;gt; %s" % (lyr, source)
del MXD
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 15 Jan 2013 14:35:53 GMT</pubDate>
    <dc:creator>FlorianRienäcker</dc:creator>
    <dc:date>2013-01-15T14:35:53Z</dc:date>
    <item>
      <title>MXD-file corrupt after changing the embedded SDE-Connection</title>
      <link>https://community.esri.com/t5/python-questions/mxd-file-corrupt-after-changing-the-embedded-sde/m-p/553895#M43266</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am facing the folling problem: We have a bunch of MXD files which contain some layers that reference a SDE as datasource.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;We are about to change our SDE-server. The new server is already running and contains the nessecary data.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As we don't want to change each MXD individually I created some bash and python scripts that should do the job for us.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am using the function "findAndReplaceWorkspacePaths" to switch the .sde connection files.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;As I want to keep the original file I use "saveACopy" to create a new MXD-file with the new connection.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;However the new MXD-file seems corrupt since I can't open it with any ArcGIS Desktop tools (ArcMap, ArcCatalog MapPathEditor) yet I can publish the MXD as a Service on our ArcGIS Server 10.0&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Basically I use the following two Scripts to change a MXD:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Create the new SDE-connection file:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
import arcpy
folderName = "/arcgisserver/geoserv/test"
fileName = "Connection_to_new_server.sde"
serverName = "SERVER-IP"
serviceName = "5151"
databaseName = ""
authType = "DATABASE_AUTH"
username = "user"
password = "pass"
saveUserInfo = "SAVE_USERNAME"
versionName = "SDE.DEFAULT"
saveVersionInfo = "SAVE_VERSION"
arcpy.CreateArcSDEConnectionFile_management (folderName, fileName, serverName, serviceName, databaseName, authType, username, password, saveUserInfo, versionName, saveVersionInfo)
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Changing the MXD:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
import arcpy 
mapdoc_in = "/source/path/source.mxd"
mapdoc_out = "/target/path/target.mxd"
sde_src = "/home/user/Connection_to_old_server.sde"
sde_target = "/home/user/Connection_to_new_server.sde"
mxd = arcpy.mapping.MapDocument(mapdoc_in)
mxd.findAndReplaceWorkspacePaths(sde_src, sde_target)
mxd.saveACopy(mapdoc_out)
del(mxd)
exit()
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When running the scripts no errors are promted.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Could it be an encoding related problem? (different encoding on the server running the script and the user's PC that created the original MXD)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;regards&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-Florian&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ps: If I check the workspace paths of all the layers of the newly created MXD they all point correctly to the new server&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt; 
[...]
MXD = arcpy.mapping.MapDocument(fullpath)
for lyr in arcpy.mapping.ListLayers(MXD):
if lyr.supports("workspacePath"):
source = lyr.workspacePath
print "%s -&amp;gt; %s" % (lyr, source)
del MXD
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Jan 2013 14:35:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/mxd-file-corrupt-after-changing-the-embedded-sde/m-p/553895#M43266</guid>
      <dc:creator>FlorianRienäcker</dc:creator>
      <dc:date>2013-01-15T14:35:53Z</dc:date>
    </item>
    <item>
      <title>Re: MXD-file corrupt after changing the embedded SDE-Connection</title>
      <link>https://community.esri.com/t5/python-questions/mxd-file-corrupt-after-changing-the-embedded-sde/m-p/553896#M43267</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think your likely problem is you have overwritten a 9.x mxd (or earlier version).&amp;nbsp; Unfortunately there isn't a means with Python that I know of to determine which mxd version the document is, but if you want to save a backup copy in 9.3 you can do this using the 2nd param (a string, e.g., '9.3') of saveACopy:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd.saveACopy (file_name, {version})&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;An idea has been posted if you'd care to add comment:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Show version of ArcGIS required to open LYR, MXD, or Layer package&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://ideas.arcgis.com/ideaView?id=087300000008M1S&amp;amp;returnUrl=%2Fapex%2FideaList%3Fc%3D09a300000004xET%26category%3DArcGIS%2BEngine"&gt;http://ideas.arcgis.com/ideaView?id=087300000008M1S&amp;amp;returnUrl=%2Fapex%2FideaList%3Fc%3D09a300000004xET%26category%3DArcGIS%2BEngine&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Jan 2013 14:51:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/mxd-file-corrupt-after-changing-the-embedded-sde/m-p/553896#M43267</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2013-01-15T14:51:57Z</dc:date>
    </item>
  </channel>
</rss>

