change the ArcSDE connection info

1214
7
12-10-2012 12:24 PM
MandyGosal
New Contributor
Is there a quick tool or method to change the ArcSDE connection info  for several (50+) layers in a MXD for version 9.3.1 and version 10?
0 Kudos
7 Replies
T__WayneWhitley
Frequent Contributor
Have you seen the thread here, using findAndReplaceWorspacePaths ---
http://gis.stackexchange.com/questions/16859/define-workspace-for-sde-connection-in-python

A connection file is accepted.
0 Kudos
T__WayneWhitley
Frequent Contributor
.......just make sure you spell it correctly, lol, you'll need a 'k' in your command, findAndReplaceWorkspacePaths
0 Kudos
AlexeyTereshenkov
Regular Contributor III
Yeah, I agree.

For ArcGIS 10 - arcpy.mapping

An example (change multiple layer sources in a single .mxd document:
01 import arcpy
02 # Define the path to the .mxd map document you want to update
03 mxd = arcpy.mapping.MapDocument(r"C:\Temp\Esri_sde_service.mxd")
04  
05 # Define which connection strings will be changed. Here there is just one connection string being changed.
06 mxd.findAndReplaceWorkspacePaths(r"C:\Users\username\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\Production@sde.sde",
07 r"C:\Users\username\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\Development@sde.sde")
08  
09 # It is possible to add more connection strings that have to be changed in the same map document
10 mxd.findAndReplaceWorkspacePaths(r"C:\Users\username\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\RasterData.sde",
11 r"C:\Users\username\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\RasterData_load.sde")
12  
13 # The path where the new .mxd map document will be saved to.
14 mxd.saveACopy(r"C:\GIS\Output\Sde_load.mxd")
15 del mxd


Another example (multiple SDE data sources in multiple.mxd map documents):
import arcpy, os
02 # Define the path to the folder where multiple .mxd map documents are stored
03 folderPath = r"C:\GIS\Maps"
04 for filename in os.listdir(folderPath):
05 fullpath = os.path.join(folderPath, filename)
06 if os.path.isfile(fullpath):
07 basename, extension = os.path.splitext(fullpath)
08 if extension.lower() == ".mxd":
09 mxd = arcpy.mapping.MapDocument(fullpath)
10  
11 # Define which connection strings will be changed. Here there are two connection strings being changed. One for vector data
12 mxd.findAndReplaceWorkspacePaths(r"C:\Users\username\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\Production@sde.sde", r"C:\Users\username\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\Development@sde.sde")
13  
14 # and second one for raster data which may have used another connection string.
15 mxd.findAndReplaceWorkspacePaths(r"C:\Documents and Settings\username\Application Data\ESRI\ArcCatalog\raster_data.sde", r"C:\Documents and Settings\username\Application Data\ESRI\Desktop10.0\ArcCatalog\raster_dataV10.sde")
16  
17 # You can use even more defitions of the connection strings that will be changed. Note that here is the update of the path from 9.3 to 10 is going on which you can see since the path to the .sde file is different (update from 9.3 to 10)
18 mxd.findAndReplaceWorkspacePaths(r"C:\Documents and Settings\username\Application Data\ESRI\ArcCatalog\TopologyData.sde", r"C:\Documents and Settings\username\Application Data\ESRI\Desktop10.0\ArcCatalog\TopologyData_manager.sde")
19 mxd.save()
20 del mxd
0 Kudos
BirajaNayak
Esri Contributor
For 9.3, you can check the following arcscript, whih you can modify as per your environment


>> ArcMAP mxd Redirect Data Sources

http://arcscripts.esri.com/details.asp?dbid=14456

>> Automate datasource change in mxd's and MXT's

http://arcscripts.esri.com/details.asp?dbid=14888
0 Kudos
JohnFell
Occasional Contributor III
All,

I have an issue where I want to use the arcpy.mapping.findReplaceWorkspacePaths method however the .mxd files that I want to update reference sde connection files that no longer exist. I don't know what the connection parameters were for the old connections and I have hundreds of .mxd files to update. What can I do in this situation? Is there a workaround to not having the original sde connection file?
0 Kudos
T__WayneWhitley
Frequent Contributor
Sounds like a 'headache' -- hopefully you have some idea what the datasources were, that they are recognizable in order to identify where to 'reroute' the connections?  'listbrokendatasources' I think is the command that could be useful for you here.

Enjoy,
Wayne
0 Kudos
JohnFell
Occasional Contributor III
Wayne,

Thanks for that tip. I've actually used that method before and the method works well for describing the original path to the data source. Unfortunately, some of these older .mxd's reference outdated versions of the geodatabase. It may be a challenge to recreate the data source name and connection that was originally referenced. Also, I've had little success in recreating the data source connection even if the geodatabase exists. Sometimes password information is stored in the .mxd that is based on windows authentication wich is another issue.
0 Kudos