`

配置式AO连接数据库

阅读更多
首先,配置文件,setup.xml
<?xml version="1.0" encoding="utf-8" ?>
<setup>
  <ConnectionString>
    <oracleconnection>Provider=MSDAORA;Persist Security Info=true;User ID=xxxx;password=xxxx;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxooxooxx)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))</oracleconnection>
    <GISUSER>xx</GISUSER>
    <SDEServer>xxooxooxx</SDEServer>
    <SDEInstance>5151</SDEInstance>
    <SDEUser>xxxx</SDEUser>
    <SDEPwd>xxxx</SDEPwd>
    <SDEDatabase>ORCL</SDEDatabase>
    <SDEVersion>SDE.DEFAULT</SDEVersion>
    <bufferDistance>5</bufferDistance>
    <filterDistance>10</filterDistance>
  </ConnectionString>
</setup>



其次,读取配置文件,
   public static string Get_Xml(string xml_name)
        {

            XmlDocument xmldoc = new XmlDocument();
            xmldoc.Load("./setup.xml");
            XmlNodeList nodelist = xmldoc.SelectSingleNode("setup").ChildNodes;//第一个节点
            string rusult = nodelist.Item(0).SelectSingleNode(xml_name).InnerText;
            return rusult;
        }

然后,连接数据库,
private void button3_Click(object sender, EventArgs e)
        {
            string sdeServer = Get_Xml("SDEServer");
            string sdeInstance = Get_Xml("SDEInstance");
            string sdeDatabase = Get_Xml("SDEDatabase");
            string sdeUser = Get_Xml("SDEUser");
            string sdePassword = Get_Xml("SDEPwd");
            string sdeVersion = Get_Xml("SDEVersion");
            double bufferDis = Convert.ToDouble(Get_Xml("bufferDistance"));
            double filterDis = Convert.ToDouble(Get_Xml("filterDistance"));
            IWorkspaceFactory sdeWorkspaceFactory;
            IFeatureWorkspace workSpace;

            try
            {
                ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);

                //授权信息加载

                ESRI.ArcGIS.esriSystem.IAoInitialize m_AoInitialize = new ESRI.ArcGIS.esriSystem.AoInitialize();
                m_AoInitialize.Initialize(ESRI.ArcGIS.esriSystem.esriLicenseProductCode.esriLicenseProductCodeArcInfo);


                //进行license控件的初始化
                IAoInitialize m_pAoInit = new AoInitializeClass();
                m_pAoInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcServer);

                IPropertySet propSet = new PropertySetClass();
                propSet.SetProperty("SERVER", sdeServer);
                propSet.SetProperty("INSTANCE", sdeInstance);
                propSet.SetProperty("USER", sdeUser);
                propSet.SetProperty("PASSWORD", sdePassword);
                propSet.SetProperty("DATABASE", sdeDatabase);
                propSet.SetProperty("VERSION", sdeVersion);

                sdeWorkspaceFactory = new SdeWorkspaceFactoryClass();
                workSpace = (IFeatureWorkspace)sdeWorkspaceFactory.Open(propSet, 0);

             //   MessageBox.Show("数据库练级成功!");
                //得到路段图层
                IFeatureClass pFCLuDuan = (workSpace as IFeatureWorkspace).OpenFeatureClass("路段");

                IFeatureLayer pFLLuDuan = new FeatureLayer();
                pFLLuDuan.FeatureClass = pFCLuDuan;
                pFLLuDuan.Name = "路段";


                ILayer pLayer = pFLLuDuan as ILayer;


                IMap pMap = axMapControl1.Map;

                pMap.AddLayer(pLayer);

                axMapControl1.ActiveView.Refresh();

            }
            catch (Exception ex)
            {

            }

        }
      
1
2
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics