在使用企業類庫時想取出單獨企業配置文件中的鏈接字符串遍歷,並放到本身的數據庫處理類中,在查找了好久的資料後都沒有找到,因而本身探索着寫了一個,共享給你們以作參考:數據庫
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