MXD-file corrupt after changing the embedded SDE-Connection

2180
1
01-15-2013 06:35 AM
FlorianRienäcker
New Contributor
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
Tags (2)
0 Kudos
1 Reply
T__WayneWhitley
Frequent Contributor
I think your likely problem is you have overwritten a 9.x mxd (or earlier version).  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:

mxd.saveACopy (file_name, {version})


An idea has been posted if you'd care to add comment:
Show version of ArcGIS required to open LYR, MXD, or Layer package
http://ideas.arcgis.com/ideaView?id=087300000008M1S&returnUrl=%2Fapex%2FideaList%3Fc%3D09a300000004x...
0 Kudos