动态修改Web.config连接字符串

来源:互联网 发布:人工智能技术培训材料 编辑:程序博客网 时间:2024/05/21 05:08


string path = VirtualPathUtility.ToAbsolute("~/");
Configuration webConfig = WebConfigurationManager.OpenWebConfiguration(path);
ConnectionStringsSection connSection = webConfig.GetSection("connectionStrings") as ConnectionStringsSection;
connSection.ConnectionStrings["SyfHospitalEntities"].ConnectionString = "aa";
webConfig.Save();
0 0