How to modify the mxd layer connection

Source: Internet
Author: User

Comrades who use mxd must have encountered the following problems:
An mxd is copied to another machine, or the SDE server is changed. After the mxd is turned on, there is an annoying red exclamation point in front of all layers. The connection is lost. What should we do at this time?

Method:
1. Manual Modification
1) disconnect the network and open mxd. The network is disconnected to speed up mxd activation;
2) connect to the network
3) on a layer, right-click and choose data> repair data source and select the SDE server or another data source type. Mxd is automatically repaired.

Disadvantages:
If we have multiple valid data sources, but want to switch the data source, you will find that the layer automatically repaired still uses the old data source. It seems that you need to modify layers one by one.

2,CodeModify
You can copy the following code to the VBA environment, modify the connection string, and execute it. You can instantly modify the data source. Isn't that great? Of course, it can also be made an independentProgramUsed to repair mxd.

Private sub idatalayerexample ()
Dim pmxdoc as imxdocument
Dim PAPP as iapplication
Set PAPP = Application
Set pmxdoc = Papp. Document
Dim player as ilayer
Dim pdatalayer as idatalayer
Dim pdatasetname as idatasetname
Dim pwsname as iworkspacename
Dim sfds as string
Dim pfcname as ifeatureclassname
Dim I as integer
For I = 0 to pmxdoc. focusmap. layercount-1
'Get Layers
Set player = pmxdoc. focusmap. layer (I)
If typeof player is idatalayer then
Sfds = ""
Set pdatalayer = pmxdoc. focusmap. layer (I)
Set pdatasetname = pdatalayer. datasourcename
Set pwsname = pdatasetname. workspacename
'Modify the connection string
Pwsname. pathname = "C: \ Documents ents and Settings \ Administrator \ Application Data \ ESRI \ arccatalog \ connection to localhost (DLG). Sde"
'Reconnect
Pdatalayer. Connect pdatasetname

'Use the following code to display the connection information
Set pdatasetname. workspacename = pwsname

If typeof pdatasetname is ifeatureclassname then
Set pfcname = pdatasetname
If not pfcname. featuredatasetname is nothing then
Sfds = pfcname. featuredatasetname. Name
End if
End if

Debug. Print "(" + format (I) + ") path:" + pwsname. pathname
Debug. Print "feature Dataset:" + sfds
Debug. Print "feature class/Dataset:" + pdatasetname. Name
Debug. Print

End if
Next I
End sub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.