I am trying to dynamically set the connection string in web.config in C# code:
ConfigurationManager.ConnectionStrings["ServerConnection"].ConnectionString = "blah";
But it’s not allowing me to do it and throwing the following error:
The configuration is read only.
NOTE: I would like to not actually save to web.config if possible. Just dynamically set it in memory.
If you don’t want to change your actual web.config then you can use;
Or you can copy the value of the connection string to another string if you want to preserve some data then do your changes..