MXD の SDE データ ソースを再設定

投稿日:2016/9/1 (木) 更新日:

Private Sub ReConnectToSDE()
    Dim pMapDocument As IMapDocument
    Set pMapDocument = New MapDocument
    pMapDocument.Open "D:\Workspace\Support\PathA.mxd"          '対象マップ ドキュメント
    Dim intMap As Integer
    For intMap = 0 To pMapDocument.MapCount - 1
        Dim pMap As IMap
        Set pMap = pMapDocument.Map(intMap)
        Dim pLayers As IEnumLayer
        Set pLayers = pMap.Layers
        Dim pLayer As ILayer
        Set pLayer = pLayers.Next
        Do Until pLayer Is Nothing
            Dim pPropertySet As IPropertySet
            Set pPropertySet = New PropertySet
            With pPropertySet
                .SetProperty "Server", "ServerName"               'サーバ
                .SetProperty "Instance", "5151"                 'インスタンス
                .SetProperty "Database", ""                     'データベース
                .SetProperty "user", "UserName"                    'ユーザ名
                .SetProperty "password", "UserPass"              'パスワード
                .SetProperty "version", "SDE.DEFAULT"           'バージョン
            End With
            Dim pDataLayer As IDataLayer
            Set pDataLayer = pLayer
            Dim pDatasetName As IDatasetName
            Set pDatasetName = pDataLayer.DataSourceName
            Dim pWorkspaceName As IWorkspaceName
            Set pWorkspaceName = New WorkspaceName
            pWorkspaceName.WorkspaceFactoryProgID = "esriDataSourcesGDB.SdeWorkspaceFactory"
            pWorkspaceName.ConnectionProperties = pPropertySet  'ArcSDE接続情報
            pDatasetName.Name = "aaa"                           'フィーチャクラス名
            Set pDatasetName.WorkspaceName = pWorkspaceName
            Set pLayer = pLayers.Next
    Next intMap
    pMapDocument.Save True, False
End Sub


-プログラミング, ArcGIS
-, ,

Copyright© WINGFIELD since1981 , 2019 All Rights Reserved.