动态修改微软企业库的连接字符串

            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            ConfigurationSection connectionConfigurationSection = config.Sections["connectionStrings"];
            ConnectionStringsSection connectionStringsSection = connectionConfigurationSection as ConnectionStringsSection;
            connectionStringsSection.ConnectionStrings["dataSource"].ConnectionString = ConStr;
            config.Save();
            ConfigurationManager.RefreshSection("connectionStrings");

            if (DataKey == null)
            {
                db = DatabaseFactory.CreateDatabase();
            }
            else
            {
                db = DatabaseFactory.CreateDatabase(DataKey);
         
            }

 

posted on 2012-09-25 14:01  飞舞的蒲公英  阅读(695)  评论(0编辑  收藏  举报