Solved

The configuration is read only.

Posted on 2006-06-13
3
3,364 Views
Last Modified: 2007-11-27
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
Comment
Question by:tz478
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
existenz2 earned 500 total points
ID: 16894187
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
 
LVL 1

Author Comment

by:tz478
ID: 16894649
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
 
LVL 14

Expert Comment

by:existenz2
ID: 16895962
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now