我目前正在开发一个ASP C#Web应用程序。我创建了一个设置页面,用于保存MySQL数据库连接设置。
我有一个ASP页面,其中包含允许用户修改MySQL数据库连接设置的表单。当用户提交表单时,它从文本框中获取值,并且应该使用新的连接设置修改设置。但是,VS2010报告的错误表明无法将属性或索引器分配给它 - 它是只读的。
如何修改这些设置。
感谢您的帮助。
Chris Board
答案 0 :(得分:1)
修改:更改变量名称
System.Configuration.Configuration updateWebConfig =
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("\\");
System.Configuration.ConnectionStringSettings conStringSettings = updateWebConfig.ConnectionStrings.ConnectionStrings["testConString"]; //your connection string name here as specified in the web.Config file
conStringSettings.ConnectionString = txtCon.Text; //Your Textbox value here
conStringSettings.CurrentConfiguration.Save();
这将打开您网站中的根web.config文件并更新其中的连接字符串。有关在运行时更新web.config的更多信息,请查看here在“更新配置设置”
下