Change Map Document Join Layers Instance

480
0
02-02-2012 11:24 PM
De_WetEllis
New Contributor III
Hi

Weve been struggling with this for a while now. We have a Mxd with over 400 layers. We switched from an sde connection to a Direct Connect.
Now when we need to publish the map to a clients server there connection settings might be different. We are required then to open the mxd and change every layers connection individually.

I wrote an application to change the instance but we have a few problems.


     IMapDocument pMapDocument = new MapDocumentClass();
                IMap pMap;
                IEnumLayer pEnumLayer;
                IFeatureLayer pFeatureLayer;
                IDataLayer2 pDataLayer;
                IDatasetName pDatasetName;
                IWorkspaceName pWorkspaceName;
                ESRI.ArcGIS.esriSystem.UID pUID = new UIDClass();

                IPropertySet pConnectionProperties = new PropertySetClass();
            
                string sPath = @FileName;

                pMapDocument.Open(sPath, "");
                pMap = null;

                for (int i = 0; i < pMapDocument.MapCount; i++)
                {
                    pMap = pMapDocument.get_Map(i);
                    pEnumLayer = pMap.get_Layers();

                    pEnumLayer.Reset();
                    for (int iss = 0; iss < pMap.LayerCount; iss++)
                    {
                        pFeatureLayer = pEnumLayer.Next() as IFeatureLayer;
                        while (pFeatureLayer != null)
                        {


                            if (pFeatureLayer.DataSourceType == "SDE Feature Class")
                            {
                                pDataLayer = pFeatureLayer as IDataLayer2;
                                if (pDataLayer.DataSourceName is IDatasetName)
                                {

                                    pDatasetName = pDataLayer.DataSourceName as IDatasetName;
                                    pWorkspaceName = pDatasetName.WorkspaceName;

                                    pConnectionProperties = pWorkspaceName.ConnectionProperties;
                                    pConnectionProperties.SetProperty("INSTANCE", "sde: oracle10g:/;LOCAL=orcl");

                                    pWorkspaceName.ConnectionProperties = pConnectionProperties;
                                }

                            }

                            pFeatureLayer = pEnumLayer.Next() as IFeatureLayer;
                        }
                    }

                }
                pMapDocument.ReplaceContents(pMap as IMxdContents);
                pMapDocument.Save(true, false);
                pMapDocument.Close();

The above code opens the Map Document and change every SDE Feature layers Datasource Instance Property to direct connection from SDE (5151).

In the process all Joins are lost and the registered Geo Database and version on the layer.
So the main reason behind the application is to take out the manual process of changing the Layer Dataset properties.

Is there a way to get and change all joins and keep the versioning.
Is there a way that we dont need to make these changes and only need to change a property in ArcMap so that the rule applies for all feature layers?

At the end of the day when the Map Document opens up eventually we need to add all the joins back because the Join still pointed to an SDE instance.

Any help will be appreciated.

Thanks

De Wet
0 Kudos
0 Replies