|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Can't set ConnectionStringSettings.ConnectionString propertyThe ConnectionString property of the ConnectionStringSettings object is
get/set, but when I try to set it to some other value I get an error, "The configuration is read only". I get the object by calling WebConfigurationManager.ConnectionStrings["production"] From this Web.Config snippet: <connectionStrings> <add name="production" connectionString="encrypted" providerName="System.Data.OracleClient" /> </connectionStrings> I don't get it. Hello Brad,
u forgot <appSettings> <connectionStrings> <appSettings> <add name="production" connectionString="encrypted" providerName="System.Data.OracleClient" /> </appSettings> </connectionStrings> BW> The ConnectionString property of the ConnectionStringSettings object BW> is get/set, but when I try to set it to some other value I get an BW> error, "The configuration is read only". BW> BW> I get the object by calling BW> WebConfigurationManager.ConnectionStrings["production"] BW> BW> From this Web.Config snippet: BW> <connectionStrings> BW> <add name="production" connectionString="encrypted" BW> providerName="System.Data.OracleClient" /> BW> </connectionStrings> BW> I don't get it. BW> --- WBR, Michael Nemtsev :: blog: http://spaces.msn.com/laflour "At times one remains faithful to a cause only because its opponents do not cease to be insipid." (c) Friedrich Nietzsche Michael Nemtsev wrote:
> Hello Brad, That doesn't work - Unrecognized element 'appSettings'.> > u forgot <appSettings> > > <connectionStrings> > <appSettings> > <add name="production" connectionString="encrypted" > providerName="System.Data.OracleClient" /> > </appSettings> > </connectionStrings> Hello Brad,
Read here http://samples.gotdotnet.com/quickstart/aspplus/default.aspx?url=/quickstart/aspplus/doc/configretrieve.aspx >> Hello Brad, BW> That doesn't work - Unrecognized element 'appSettings'.>> >> u forgot <appSettings> >> >> <connectionStrings> >> <appSettings> >> <add name="production" connectionString="encrypted" >> providerName="System.Data.OracleClient" /> >> </appSettings> >> </connectionStrings> --- WBR, Michael Nemtsev :: blog: http://spaces.msn.com/laflour "At times one remains faithful to a cause only because its opponents do not cease to be insipid." (c) Friedrich Nietzsche Michael Nemtsev wrote:
> Hello Brad, If I'm not mistaken, that page shows how to access config values the 1.0 > > Read here > http://samples.gotdotnet.com/quickstart/aspplus/default.aspx?url=/quickstart/aspplus/doc/configretrieve.aspx way (ConfigurationSettings.AppSettings). The object to access the same AppSettings collection in 2.0 is WebConfigurationManager.AppSettings (there's a different object for winform apps). My issue does not concern the AppSettings collection; it concerns the ConnectionStrings collection that is new with 2.0. In 2.0 you can declare a separate section like this in your config: <connectionStrings> <add name="test" connectionString="" providerName="System.Data.OleDb" /> <add name="production" connectionString="" providerName="System.Data.OracleClient" /> </connectionStrings> To access the test connection string in code you would call WebConfigurationManager.ConnectionStrings["test"] to get a ConnectionStringSettings object All this works fine; I'm having trouble setting the connection string property of the ConnectionStringSettings object after reading it in from the config (I have it encrypted in the config, I need to decrypt it after I read it in). Ahh, I missed that u changes this values.
Well, I reckon it's impossible in this way. Deal with this file with XML classes, open - find the node and change values/attributes Show quote > The ConnectionString property of the ConnectionStringSettings object is > get/set, but when I try to set it to some other value I get an error, > "The configuration is read only". > > I get the object by calling > WebConfigurationManager.ConnectionStrings["production"] > > From this Web.Config snippet: > <connectionStrings> > <add name="production" connectionString="encrypted" > providerName="System.Data.OracleClient" /> > </connectionStrings> -- WBR, Michael Nemtsev :: blog: http://spaces.msn.com/laflour "At times one remains faithful to a cause only because its opponents do not cease to be insipid." (c) Friedrich Nietzsche Michael Nemtsev wrote:
> Ahh, I missed that u changes this values. That would be way more trouble than it's worth - it would be easier to > Well, I reckon it's impossible in this way. > Deal with this file with XML classes, open - find the node and change > values/attributes simply put my connection string (and the provider invariant necessary to create 2.0 generic DBFactories) back in my AppSettings collection. My question remains, however - why the heck can't I call a property setter? Hello Brad,
>> Ahh, I missed that u changes this values. BW> That would be way more trouble than it's worth - it would be easier>> Well, I reckon it's impossible in this way. >> Deal with this file with XML classes, open - find the node and change >> values/attributes BW> to simply put my connection string (and the provider invariant BW> necessary to create 2.0 generic DBFactories) back in my AppSettings BW> collection. BW> BW> My question remains, however - why the heck can't I call a property BW> setter? Because it's readonly property ;) --- WBR, Michael Nemtsev :: blog: http://spaces.msn.com/laflour "At times one remains faithful to a cause only because its opponents do not cease to be insipid." (c) Friedrich Nietzsche Michael Nemtsev wrote:
> Hello Brad, I don't get it; the object has a getter and a setter. If it were a read > Because it's readonly property ;) only property, it would only have a getter. Right? WebConfigurationSettings.ConnectionStrings["production"] gets the
ConnectionStringsSettings for the connection string named "production". This is read only. However, WebConfigurationSettings.ConnectionStrings["production"].ConnectionString has get/set functionality and can be used to change the connection string itself. -- Show quoteChristopher A. Reed "The oxen are slow, but the earth is patient." "Brad Wood" <bradley|.wood|@ndsu|.edu> wrote in message news:ejHSzhZMGHA.3728@tk2msftngp13.phx.gbl... > The ConnectionString property of the ConnectionStringSettings object is > get/set, but when I try to set it to some other value I get an error, "The > configuration is read only". > > I get the object by calling > WebConfigurationManager.ConnectionStrings["production"] > > From this Web.Config snippet: > <connectionStrings> > <add name="production" connectionString="encrypted" > providerName="System.Data.OracleClient" /> > </connectionStrings> > > I don't get it. Christopher Reed wrote:
> WebConfigurationSettings.ConnectionStrings["production"] gets the Exactly. So why on earth am I getting "The configuration is read only" > ConnectionStringsSettings for the connection string named "production". > This is read only. However, > WebConfigurationSettings.ConnectionStrings["production"].ConnectionString > has get/set functionality and can be used to change the connection string > itself. when I try to change the connection string? Is the file itself read only?
-- Show quoteChristopher A. Reed "The oxen are slow, but the earth is patient." "Brad Wood" <bradley|.wood|@ndsu|.edu> wrote in message news:eG40VAwMGHA.1132@TK2MSFTNGP10.phx.gbl... > Christopher Reed wrote: >> WebConfigurationSettings.ConnectionStrings["production"] gets the >> ConnectionStringsSettings for the connection string named "production". >> This is read only. However, >> WebConfigurationSettings.ConnectionStrings["production"].ConnectionString >> has get/set functionality and can be used to change the connection string >> itself. > > Exactly. So why on earth am I getting "The configuration is read only" > when I try to change the connection string? "Christopher Reed" wrote: As a matter of fact it's not, but I don't want to update my config file; I > Is the file itself read only? just want to convert what I read in from the config file (encrypted) to decrypted. Nothing in the docs indicates that the ConnectionStringSettings object does anything other than contain the properties that exist in my config, and the ConnectionString property is get/set. Are you accessing this web.config from your local machine or remotely?
-- Show quoteChristopher A. Reed "The oxen are slow, but the earth is patient." "Brad" <B***@discussions.microsoft.com> wrote in message news:0B691E6E-13D5-46CE-938A-2DF7C12002B8@microsoft.com... > "Christopher Reed" wrote: > >> Is the file itself read only? > > As a matter of fact it's not, but I don't want to update my config file; I > just want to convert what I read in from the config file (encrypted) to > decrypted. Nothing in the docs indicates that the > ConnectionStringSettings > object does anything other than contain the properties that exist in my > config, and the ConnectionString property is get/set. "Christopher Reed" wrote: Locally. The same error occurs when running a simple console app sample:> Are you accessing this web.config from your local machine or remotely? // add this element to an App.Config <connectionStrings> <add name="test" connectionString="string in config" providerName="" /> </connectionStrings> // console app using System; using System.Configuration; // add reference namespace ConsoleApplication1 { class Program { static void Main( string[] args ) { ConnectionStringSettings css = ConfigurationManager.ConnectionStrings["test"]; Console.WriteLine( css.ConnectionString ); css.ConnectionString = "modified"; // run time error here Console.ReadLine(); } } } |
|||||||||||||||||||||||