Reputation: 36237
I am currently developing a ASP C# web application. I have created a settings page which is going to hold MySQL Database Connection Settings.
I have an ASP page with a form that allows the user to modify the MySQL Database connection settings. When the user submits the form it gets the value from the text boxes and is supposed to modify the settings will with the new connection settings. However, VS2010 is reporting an error that says property or indexer cannot be assigned to -- it is read only.
How can I go about modify these settings.
Thanks for your help.
Chris Board
Upvotes: 0
Views: 374
Reputation: 5129
Edit: Change variable names
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();
This will open the root web.config file in your website and update the connection string there. For more information on updating the web.config in runtime look here Under "Updating Configuration Settings"
Upvotes: 1