Change connection properties of layers in an .mxd without actually opening it?

744
4
02-10-2012 06:08 AM
JeremyRead
New Contributor II
Does anyone know if there is a way to do this?

We will soon be changing the name of one of our servers that we have been connecting to for many years.  The problem with this is that we have literally thousands of .mxds with connections saved to the old server name, and they will all be broken when the name goes away.

Rather than have people manually repair all of these .mxds (which would take forever), we would like to write a tool that will search for all files in a directory with the .mxd extension, find any layers in the .mxds with connections to the old server name, and programmatically switch them to the new server name.  All this without actually having to open the .mxds in ArcMap.

Any suggestions would be most-appreciated.
0 Kudos
4 Replies
NeilClemmons
Regular Contributor III
Use IMapDocument.
0 Kudos
JeremyRead
New Contributor II
Thanks, Neil, I will take a look at it 🙂
0 Kudos
AlexanderGray
Occasional Contributor III
Second that for the IMapDocument.  Also use IDatalayer2.Disconnect and IDatalayer2.Connect.  This will avoid the program crashing if the layer sources were broken.

 
        Dim dataLay2 As IDataLayer2 = TryCast(m_layer, IDataLayer2)
        dataLay2.Disconnect() 
        Dim newfc As IFeatureClass = fWork.OpenFeatureClass(fcFullName)
        Dim ds As IDataset = CType(newfc, IDataset)
        dataLay2.DataSourceName = ds.FullName
        dataLay2.Connect(CType(fcName, IName))
0 Kudos
JeremyRead
New Contributor II
Well, I've muddled through this to some extent.  I have it working for the most part, but I am plagued by some annoyances:

I am using the IPropertySet GetProperty and SetProperty methods on the server/instance with success, however we use versioned editing environments and "broken" layer files, which require people to login with their own username/password when they open a .mxd and choose their edit version.  I am trying to figure out how I can pass this information from text boxes on the form *before* I get prompted by the default pop up forms from ArcGIS.

The problem is that once IMapDocument.Open() is called, it opens the .mxd and starts prompting you for your login info and edit version.  If this connection modification process is to be automated for thousands of maps, the user can't just sit there selecting the things on the pop up dialog for hours straight.  Is there *any* way to pass these parameters initially before IMapDocument.Open() is called?  As in "Open As" server/instance, with user/password, with certain edit version?

Thank!
0 Kudos