Single MXD Broken SDE Links

3299
7
08-31-2015 11:19 AM
lelaharrington
New Contributor III

i have a mxd that has broken SDE links ( well i have a lot of them) i am fine running a script one mxd at a time to repair the broken sources. some of the features are now in feature classes, to clean up the SDE location. some are still there. how do i write  a script that will look to the mxd i want it to and repair the SDE connection to find the feature.

also if the feature had been renamed how do i tell the the script to look for (old) and replace with (new)

i have looked at the generic "repair broken sources script" and i just cannot wrap my head around how to use this.

0 Kudos
7 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Lela,

Have you taken a look at the following help doc?

Updating and fixing data sources with arcpy.mapping—Help | ArcGIS for Desktop

This will give you script examples for different scenarios.

0 Kudos
lelaharrington
New Contributor III

i have and i honestly cant understand it.

i have the connection it needs to go to and the connection it came from but i an not sure how to actually write it

0 Kudos
JakeSkinner
Esri Esteemed Contributor

You would need to write something like below:

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project_default.mxd")
mxd.findAndReplaceWorkspacePaths(r"C:\Project\Old Connection.sde", r"C:\Project\New Connection.sde")
mxd.save()
del mxd

lelaharrington
New Contributor III

yes! that is the script i am using however the part on it that says mxd.findAndReplaceWorkspacePaths(r"C:\Project\Old Connection.sde..."

that is the part i cannot seem to get right. if my SDE is a database connection in arc catalog how to i write the C:\Project. part?

0 Kudos
lelaharrington
New Contributor III

if it helps these are sql servers i am trying to basically tell the script

if the old connection is something like WBlmnpoGOGIS04 server then now connect to the KCF GIS PROD on KCF-GLE-SQL1.sde. i just don't know who to write the connections in.

0 Kudos
JakeSkinner
Esri Esteemed Contributor

To access your SDE connections under 'Database Connections', you can use something similar to:

r"Database Connections\SQLServer.sde"

Ex:

import arcpy 
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project_default.mxd") 
mxd.findAndReplaceWorkspacePaths(r"Database Connections\Old Connection.sde", r"Database Connections\New Connection.sde") 
mxd.save() 
del mxd
0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

I just posted a python addin Python addin for data inventory and “broken-link” repair.   If nothing else, using the first three tools will help you see all the FGDBs, feature classes, and broken links.

There is no such thing as a once size fits all when it comes to fixing broken links, but this can fix changing types, changing paths, updating .sde and .ags layers, etc.   The repair requires a modified .csv file that is output from the broken link tool.  I do not have any good samples of the file yet, but will try to get something posted by end of business.