0

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

1
  • 2
    @Chris - can you post the code that you're using to try and do this at the moment? Commented Apr 10, 2011 at 13:57

1 Answer 1

1

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"

Sign up to request clarification or add additional context in comments.

4 Comments

Hi, i'm not using a connection string from the web.config I've made a Settings.settings file under the properties options on VS2010 and I want to be able to update that
@Boardy If you use the settings.setting file you cannot write to an application level setting as it is read-only (Which a connection string should be). Web.Config (In my opinion) is the best way to save connection strings, you can even encrypt it (by using aspnet_regiis) and it's pretty straight forward. See here for more details on settings.setting file msdn.microsoft.com/en-us/library/aa730869(v=vs.80).aspx Any reason why you would want to use the settings option?
Thanks for your help. I have used the web.config file as you suggested. I'm new to ASP and wasn't completely sure what the difference was. Thanks again
@Boardy, It's a pleasure, glad it helped

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.