获取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”为企业类库单独配置节的Sectionspa

相关文章
相关标签/搜索