Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Using the mxd.findAndReplaceWorkspacePaths method, if and MXD is updated and the path the the .sde connection file moves again all of the data sources will break again.

Is there a method to permanently update each SDE layer in an MXD Table of Contents to permanently store the SDE Server and Service? Ie. Just replace the SERVER and INSTANCE for each SDE layer in an MXD using python or ArcObjects in Pyhton?

share|improve this question
    
So far as I know, Arcmap always uses the path to the connection file, e.g. "Database Connections\Connection to Foobar.sde", and there is no way to just pass or save the SERVER and SERVICE info directly. I would be delighted to be proven wrong. I can imagine a hack to store a dynamically generated sde file in the same directory as the mxd, or even perhaps inside the mxd, and then refer to that instead; don't know how to implement it though. –  matt wilkie Aug 29 '12 at 21:35
1  
@matt, I don't think that's completely correct; ArcMap will use the connection properties persisted within the layer. The SDE connection file is never looked at again, its path is only metadata. The problem here seems to be specific to the arcpy data source replacement methods. You can definitely set connection properties without using a connection file with ArcObjects (e.g. using the IWorkspaceName interface). However with arcpy you are limited to the methods provided. –  blah238 Aug 29 '12 at 23:00
    
@matt you are correct. I'm using the Arcpy methods. I can't get the connection properties for each layer to 'save'. A dependence for obtaining connection properties from the path to the connection file remains after an mxd.save() or mxd.saveACopy() –  MMV Aug 30 '12 at 14:57
add comment

2 Answers

This may be too simple but...
If you rename the old connection and name the new one with the old name does that accomplish a better result?

share|improve this answer
    
If you re-point every Layer in an MXD to use a connection file located at '\\corpshare\sde\corpsde.sde' everything works great. If however that path becomes unavailable, every MXD is now broken.' I am more interested in the connection properties SERVER and SERVICE within the connection file, rather than the path to it. I want to essentially update each Layers SERVER and SERVICE, so if that path becomes unavailable the MXD can still access the server without a path to a valid connection file. –  MMV Aug 29 '12 at 21:07
    
@MMV, are you sure? I just tried it: 1) Add a layer to map using an SDE connection file 2) Save the MXD and close ArcMap 3) Delete/rename SDE connection file 4) Open saved MXD. The layer loads without a problem. –  blah238 Aug 29 '12 at 23:18
    
@Blah238 correct I have seen this - if the sde file is gone it still connects ??? What I thought is that if your change the connection properties in an sde file (to point it to another server/service that it would find it. (as ong as you don't open and break the links first. I will try it out and get back. –  Brad Nesom Aug 29 '12 at 23:53
    
Just read blah238's post above. I wasn't aware of that. because I have had password issues before and fixed them by changing the connection strings. perhaps the trick is to break it and repair it with the new connection strings. but to break it you have to stop the existingg service. ?? –  Brad Nesom Aug 30 '12 at 0:12
    
@blah238 By manually creating an MXD in ArcMap, saving it and removing the connection file everything will continue to work after the path to the .sde file has been 'broken'. Updating an already existing MXD using ArcPy, it's where the dependence on the path to the connection file remains. –  MMV Aug 30 '12 at 14:59
show 1 more comment
up vote 3 down vote accepted

I have found a solution to breaking the dependence on path to the .sde connection file using ArcPy and the following method.

This way works:

lyr.replaceDataSource(sdeConn, "SDE_WORKSPACE", lyr.datasetName, False) table.replaceDataSource(sdeConn, "SDE_WORKSPACE", lyr.datasetName, False)

You can rename or delete the connection file after the MXD has been repaired and saved. It will continue to open without issue after the connection file is no longer there.

These methods DO NO work:

mxd.findAndReplaceWorkspacePaths

lyr.findAndReplaceWorkspacePath

You CANNOT rename or delete the connection file after the MXD has been repaired. The MXD will look for the .sde connection file in the same location always each time it's opened.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.