Solved

The configuration is read only.

Posted on 2006-06-13
3
3,362 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

8 Experts available now in Live!

Get 1:1 Help Now