• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3402
  • Last Modified:

The configuration is read only.

I am trying to use the following code to add a connection string to the web.config at runtime.  I got an error says "The configuration is read only."  Any ideas?  

         Dim conn As New ConnectionStringSettings
         conn.ConnectionString = "Data Source=xx;Persist Security Info=True;User ID=xx;password=xx;"
         conn.Name = "myConn"
         conn.ProviderName = "System.Data.OracleClient"
         ConfigurationManager.ConnectionStrings.Add(conn)

I am using Visual Studio 2005.   I am developing a web app.    Thanks!
0
tz478
Asked:
tz478
  • 2
1 Solution
 
existenz2Commented:
The default configuration files are meant to be read only by (good) design. If you want to save additional information you need to use resource files or custom config files together with custom classes which read/write the config files.
0
 
tz478Author Commented:
The above code comes from Wrox "Professional ASP.NET 2.0" Chapter 11 P351.  They did not mention anything about read only.

Well, I guess I have to take your word - the web.config is read only by design.  Thanks!
0
 
existenz2Commented:
I had another look at it when you mentioned 2.0, I assumed you were using 1.1 (my bad, should have known that considering the code you posted), and although I still stick to my point that you should threat the web.config as a read only file, in .NET 2.0 you are able to read/write data into the appsettings and connectionString tags inside the web.config. It has big cons.

You can do this with (some examples):
http://www.dotnetspider.com/qa/Question42231.aspx
http://msdn2.microsoft.com/en-us/system.web.configuration.webconfigurationmanager.aspx
http://www.developersdex.com/asp/message.asp?p=1116&r=5053428
http://www.odetocode.com/Articles/418.aspx

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now