florian_rienaecker

MXD-file corrupt after changing the embedded SDE-Connection

Discussion created by florian_rienaecker on Jan 15, 2013
Latest reply on Jan 15, 2013 by Wayne_Whitley
Hi,

I am facing the folling problem: We have a bunch of MXD files which contain some layers that reference a SDE as datasource.
We are about to change our SDE-server. The new server is already running and contains the nessecary data.

As we don't want to change each MXD individually I created some bash and python scripts that should do the job for us.

I am using the function "findAndReplaceWorkspacePaths" to switch the .sde connection files.
As I want to keep the original file I use "saveACopy" to create a new MXD-file with the new connection.
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

Basically I use the following two Scripts to change a MXD:

Create the new SDE-connection file:

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)


Changing the MXD:
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()


When running the scripts no errors are promted.

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)

regards
-Florian

ps: If I check the workspace paths of all the layers of the newly created MXD they all point correctly to the new server

 
[...]
MXD = arcpy.mapping.MapDocument(fullpath)
for lyr in arcpy.mapping.ListLayers(MXD):
if lyr.supports("workspacePath"):
source = lyr.workspacePath
print "%s -> %s" % (lyr, source)
del MXD

Outcomes