On one of our projects, I have been creating .mxd Files that reference a PostgreSQL Database. For some corporate reasons, the database had to be relocated to a new server, leaving all the mxd connections broken.
This was supposed to be a simple correction with python and the arcpy library. I have been running into some issues, though. Here is the code I've been using to achieve said purpose:
import arcpy import os mxdPath = r"..." #Path where the files are stored originalRef = "Database Connections\Connection to xxx-180.sde" newRef = "Database Connections\Connection to new-server.sde" for root, dirs, filenames in os.walk(mxdPath): for f in filenames: mxd_path = os.path.join(root, f) mxd = arcpy.mapping.MapDocument(mxd_path) mxd.findAndReplaceWorkspacePaths(originalRef, newRef) #Point where execution halts. mxd.save() del mxd
The problem is: This script takes forever to run (it's working, but taking over 2 hours on a single file!). I have tried debugging it, and apparently, the findAndReplaceWorkspacePaths takes just too long to update (I would guess that as the layers start to be updated, the program tries to redefine the query layers to the connection that no longer exists, but doesn't recognize it immediately. I am running into the same problem while opening the files per se with ArcMap - a long wait until the document manages to load).
What could be done?
I was hoping there was a way to pause the reloading of the query layers and then reenabling them.