获取配置文件数据库名称

      ReadConfig("Noah.BSP", ref connect, ref database);
           
            string TableName = database + ".dbo.OUM_Organization";

    /// <summary>
        /// xml读取配置文件
        /// </summary>
        private void ReadConfig(string DataBaseAlias, ref string connect, ref string database)
        {
            string ss = string.Empty;
            DataBaseAlias = DataBaseAlias.ToLower();
            string path = HttpRuntime.AppDomainAppPath + "\\Inspur.Finix.config";
            XmlTextReader reader = new XmlTextReader(path); // new一个XMLTextReader实例 
            XmlDocument doc = new XmlDocument();
            doc.Load(reader);// 
            reader.Close();//关闭reader,不然config文件就变成只读的了 
            XmlNodeList nodeList = doc.SelectSingleNode("//components").ChildNodes;
            foreach (XmlNode n in nodeList)
            {
                if (DataBaseAlias == n.Attributes["name"].Value.ToLower())
                {
                    ss = n.FirstChild.Attributes["name"].Value;
                }
            }  //end foreach

            if (!string.IsNullOrEmpty(ss))
            {
                if (ss.Contains("server"))
                    ss = ss.Replace("server", "Data Source");
                string[] strs = ss.Split(';');
                if (strs.Length >= 4)
                {
                    connect = strs[0] + ";" + strs[1] + ";" + strs[2] + ";";
                    database = strs[3].Split('=')[1];
                }
            }
        }

posted @ 2014-09-24 10:04  郭郭郭  阅读(545)  评论(0编辑  收藏  举报