 |
|
 |
Hi,
i hav tried this application.but everytime the value is retriving is the old one..means the connection string is not changing with that new value..
|
|
|
|
 |
|
 |
Hello
good job with how to change the values of appconfig.
but I have a doubt, how can I use?
My problem:
dim conn as New SqlConnection (My.Settings.MydatabaseConnectionString)
and i use like this
but with the appconfig of your project can change the server, database, user and password, but as I refer to:
Dim conn As New SqlConnection (here?)
or otherwise, is that I do not know!
I await your response as soon as possible
|
|
|
|
 |
|
 |
values not changing... only retrieving the values..
|
|
|
|
 |
|
 |
Thank you, this is the best post online on this subject. HOWEVER... I'm very new to development so please bear with me a moment! Also I'm converting your VB examples to C#.
Jatin, I first tried your approach but I kept getting the error "Non-invocable member 'System.Xml.XmlNode.Attributes' cannot be used like a method" on "Attributes" in this section of code:
(XmlNode xNode in xElement.ChildNodes)
{
if (xNode.Attributes(0).Value == KeyName)
{
xNode.Attributes(1).Value = KeyValue;
}
So then I tried David Hays' suggestion, which is giving me a different error "Non-invocable member 'System.Configuration.AppSettingsSection.Settings' cannot be used like a method." on the term "System" in this section of code:
// Update the setting.
config.AppSettings.Settings(KeyName).Value = KeyValue;
// Save the configuration file.
Its strange because the Intellisense allows these actions to be entered but then complains about them.
I must be missing something... but what? Thank You!!
|
|
|
|
 |
|
 |
Which version of .net framework you are using ?
because i think this code will work with framework 2.0 , but i have not tested for other framework web.config file
|
|
|
|
 |
|
 |
Oh, thank you so much for your reply! I'm using Visual Studio 2008 with .NET 3.5, and Windows Forms with App.config, not Web.Config. Maybe I should select the .NET 2.0 option as a last resort (not sure if that will impact my project tho). If you have suggestions on implementation on my version, that would be wonderful!
|
|
|
|
 |
|
 |
Drats, I thought it would work if I re-wrote the app, this time selecting .NET Framework 2.0 instead of 3.5, but still I get the exact same error:
Non-invocable member 'System.Xml.XmlNode.Attributes' cannot be used like a method.
As I mentioned, I'm REALLY new to development so it could be something basic that I haven't done. Also, I did convert from your VB code to C#, which may have something to do with it. Any other suggestions? Thank You!
|
|
|
|
 |
|
 |
For C# use: xNode.Attributes[0].Value instead xNode.Attributes(0).Value
if (xNode.Attributes[0].Value == KeyName)
{
xNode.Attributes[1].Value = KeyValue;
|
|
|
|
 |
|
 |
Thanks for posting this code.
I am getting this error while using this code in my installer. Any idea to remove this? I am using visual studio 2005 and c#.
7/30/2010 5:18:09 PM System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
at System.Xml.XmlDocument.Load(String filename)
at GSTReturn.InstallDB.WriteAppConfig(String ServerName)
|
|
|
|
 |
|
 |
I am using webservice in window application.
There is app.config file. In which i see the following line when i change the behaviour to dynamic.
http://localhost:1442/NDTWebService/Service.asmx
actually i also have to change the web reference at runtime. user can select any server and web service reference of that server should be changed accordingly his selection .So please tell me how to change innertext of node in this app.config file
It is very urgent to me...Please do the need as early as possible..
thanks in advance....
|
|
|
|
 |
|
 |
Why didn't you just use the System.Configuration.ConfigurationManager class? This class is provided for accessing and updating configuration files. Then your Sub would only need four lines of code and would have looked like this:
Public Shared Sub UpdateAppSettings(ByVal KeyName As String, ByVal KeyValue As String)
Dim config As System.Configuration.Configuration = _
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
config.AppSettings.Settings(KeyName) = KeyValue
config.Save(ConfigurationSaveMode.Modified)
ConfigurationManager.RefreshSection("appSettings")
End Sub
And thanks to the last line, you have the added advantage that you do not need to stop and restart the application for the change to take effect!
Regards
David
|
|
|
|
 |
|
 |
yes, this solution is also good one. its acceptable..
Thanks..
|
|
|
|
 |
|
 |
' Update the setting.
config.AppSettings.Settings(KeyName) = KeyValue
>>>>must be
config.AppSettings.Settings(KeyName).Value = KeyValue
|
|
|
|
 |
|
 |
Thank you, this is the best post online on this subject. HOWEVER... I'm very new to development so please bear with me a moment! Also I'm converting your VB examples to C#.
Jatin, I first tried your approach but I kept getting the error "Non-invocable member 'System.Xml.XmlNode.Attributes' cannot be used like a method" on "Attributes" in this section of code:
(XmlNode xNode in xElement.ChildNodes)
{
if (xNode.Attributes(0).Value == KeyName)
{
xNode.Attributes(1).Value = KeyValue;
}
So then I tried David Hays' suggestion, which is giving me a different error "Non-invocable member 'System.Configuration.AppSettingsSection.Settings' cannot be used like a method." on the term "System" in this section of code:
// Update the setting.
config.AppSettings.Settings(KeyName).Value = KeyValue;
// Save the configuration file.
Its strange because the Intellisense allows these actions to be entered but then complains about them.
I must be missing something... but what? Thank You!!
|
|
|
|
 |
|
 |
For C# use: xNode.Attributes[0].Value instead xNode.Attributes(0).Value
if (xNode.Attributes[0].Value == KeyName)
{
xNode.Attributes[1].Value = KeyValue;
//...
|
|
|
|
 |
|
 |
here's an article i posted a while ago about this thing:
http://www.codeproject.com/csharp/ConfigurationSettingsRW.asp
the idea doesn't seem to be popular.. i got the same messages saying that you don't want to modify your settings at runtime. i think the people saying this don't have enough experience.. or imagination.. there are several scenarios you can imagine that would require modifying some of your settings.
|
|
|
|
 |
|
 |
yes, you are right ,agree with you, every problem have more than one solution. but if people will find all different solution, then they have variety of option to solve such kind of problems.
|
|
|
|
 |
|
 |
Alexandru Stanciu wrote: i think the people saying this don't have enough experience.. or imagination.. there are several scenarios you can imagine that would require modifying some of your settings.
I can imagine lots of scenarios. Heck, i implemented enough of them, and got bit when customers upgraded, or their admins tried to install the software on a Terminal Services box, or use limited user accounts.
I'm sure there are scenarios where it makes sense to do something like this. I'm just as sure you want to think long and hard about it before making that call - 'cause it doesn't end with code like this, it ends when you've handled all the scenarios that start out "two users are configuring the app on one machine..." or "user accounts on this box don't have write access to Program Files..."
And that's hidden, see. You aren't gonna hit that on your dev box, you have to actively code for those scenarios, and actively test that you got it right. It's no where near as simple as it looks.
----
It appears that everybody is under the impression that I approve of the documentation. You probably also blame Ken Burns for supporting slavery.
--Raymond Chen on MSDN
|
|
|
|
 |
|
 |
The config file system is set up the way it is for a reason: you don't usually want to overwrite application settings at run-time. Depending on how your app is installed, it might well not even have write access to the file. User-configurable changes should be saved to a user-specific config file, and .NET 2.0 already provides support for this.
----
It appears that everybody is under the impression that I approve of the documentation. You probably also blame Ken Burns for supporting slavery.
--Raymond Chen on MSDN
|
|
|
|
 |
|
 |
this article will help to those people who want to modify the appSettings Paramters value.
|
|
|
|
 |
|
 |
Am i misunderstanding what you're doing though? Writing changes to the configuration file that will apply to all users the next time they restart the app?
I'm not saying there aren't situations where this wouldn't be useful, but perhaps you could describe a few of them... certainly, this is a terrible way to persist any user-specific preferences.
----
It appears that everybody is under the impression that I approve of the documentation. You probably also blame Ken Burns for supporting slavery.
--Raymond Chen on MSDN
|
|
|
|
 |
|
 |
Yes May be,
Because this article will helpful , when we are installing Windows application and Set up application Configuration parameters. Because today i faced this problem and found solution for my application, thats why i have posted this article.
i dont know, what you are understanding...
|
|
|
|
 |
|
 |
Jatin Prajapati wrote: i dont know, what you are understanding...
I'm seeing a class that will allow you to write changes to the configuration file for the current app. Not the user settings file, the configuration file shared by all users. And i think that, in most scenarios, this is a spectacularly bad idea. Because it requires the app to have write access to this file, because the changes will apply to all users, because if two users make changes to the same setting only one will "win"...
So. If you needed this for something, or you see a scenario where this would be useful and appropriate, please share them!
I spend nearly every week fighting with 3rd-party code that thinks it's appropriate to write to whatever part of the system they feel like whenever they feel like it. I cannot overstate how severe this problem is, or the danger that comes from encouraging this behavior. So what i want you to do is, explain how this is not a solution for general use, but how in very specific scenarios it might be necessary.
----
It appears that everybody is under the impression that I approve of the documentation. You probably also blame Ken Burns for supporting slavery.
--Raymond Chen on MSDN
|
|
|
|
 |
|
 |
Ok, What should i Do ?
|
|
|
|
 |
|
 |
Ok well, i dont know, how many times user will update configuration settings and how many user will update same file at a time. but this Configuration settings is First Time Setup Configuration. Its not like Database application like Add/Edit/Delete every time with Multi user.
that is depend on users requirements. How user want to use Code and for which purpose.
|
|
|
|
 |