zoukankan      html  css  js  c++  java
  • 获取EnterpriseLibrary企业库配置文件中ConnectionStrings(原创)

    在使用企业类库时想取出单独企业配置文件中的连接字符串遍历,并放到自己的数据库处理类中,在查找了很久的资料后都没有找到,于是自己探索着写了一个,共享给大家以做参考:

    ConfigurationSourceSection sec = (ConfigurationSourceSection)ConfigurationManager.GetSection("enterpriseLibrary.ConfigurationSource");
                PolymorphicConfigurationElementCollection<ConfigurationSourceElement> po = (PolymorphicConfigurationElementCollection<ConfigurationSourceElement>)sec.Sources;
    
                FileConfigurationSourceElement ele = (FileConfigurationSourceElement)po.Get(0);
    
                string filepath = ele.FilePath;
                ConfigXmlDocument dc = new ConfigXmlDocument();
                string path = AppDomain.CurrentDomain.BaseDirectory + filepath;
                dc.Load(path);
                foreach (XmlNode item in dc.SelectNodes("configuration/connectionStrings/add"))
                {
                    string name = item.Attributes["name"].Value;
                    string connectionString = item.Attributes["connectionString"].Value;
                    
                }

    其中的“enterpriseLibrary.ConfigurationSource”为企业类库单独配置节的Section

  • 相关阅读:
    新人讲解
    为人处世
    项目管理
    读书
    游戏
    总结反思
    地图相关
    产品经理
    摄影
    Java 邮件发送
  • 原文地址:https://www.cnblogs.com/FirstCode/p/3227833.html
Copyright © 2011-2022 走看看