473,568 Members | 3,124 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Programmaticall y write to app.config file in vb.net code

Using the visual studio.net text editor, I know how to
enter/change the "key/value" in the app.config file, for
example:

key="SqlConnect ion1.Connection String" value="data
source=Boomer;i nitial catalog=TimeDb; integrated
security=SSPI;p ersist security info=False;work station
id=BOOMER;packe t size=4096"

But I want to be able to change some values, (e.g. data
source string) in vb code programmaticall y at run time.
Can this be done? If so, how?

Thanks in advance for your help.

Nov 19 '05 #1
4 36046
Hello,

"jasiglam" <ju*********@ho tmail.com> schrieb:
Using the visual studio.net text editor, I know how to
enter/change the "key/value" in the app.config file, for
example:

key="SqlConnect ion1.Connection String" value="data
source=Boomer;i nitial catalog=TimeDb; integrated
security=SSPI;p ersist security info=False;work station
id=BOOMER;packe t size=4096"

But I want to be able to change some values, (e.g. data
source string) in vb code programmaticall y at run time.
Can this be done? If so, how?


You can do that using the XML classes contained in the framework.
Nevertheless the config file should not be modified by the application.

HTH,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet
Nov 19 '05 #2
Hi Jasiglam,

There's a help topic: Introduction to Dynamic Properties,
ms-help://MS.VSCC/MS.MSDNVS/vbcon/html/vboriintroducti ontoapplication setting
storage.htm

Unfortunately everywhere that it talks about changing the config items,
it says to open the file in an editor and type away!!

As it's an XML file, however, you should be able to read it in, change
it and write it back out again using an XMLDocument. I say "should" because
the file may be locked during execution - I don't know.

You should be aware that "app.config " is used when developing but your
program, "appFoo", say, will use "appFoo.exe.con fig".

If you are talking about a web app, changes to the config file cause the
web app to restart.

Good luck,
Fergus
Nov 19 '05 #3
You shouldn't actually be doing this, because app.config files are
application configuration, and not application preferences configuration,
but if you must, the XML classes (In the System.XML namespace) will help
you.

--
Happy to help,
-- Tom Spink
(th**********@n tlworld.com)

"Go down with your server"

http://dotnetx.betasafe.com >> On The Mend

Please respond to the newsgroup,
so all can benefit
"jasiglam" <ju*********@ho tmail.com> wrote in message
news:00******** *************** *****@phx.gbl.. .
Using the visual studio.net text editor, I know how to
enter/change the "key/value" in the app.config file, for
example:

key="SqlConnect ion1.Connection String" value="data
source=Boomer;i nitial catalog=TimeDb; integrated
security=SSPI;p ersist security info=False;work station
id=BOOMER;packe t size=4096"

But I want to be able to change some values, (e.g. data
source string) in vb code programmaticall y at run time.
Can this be done? If so, how?

Thanks in advance for your help.

Nov 19 '05 #4
Thank you for your time and help. In my application, I
need to change the connection string to a database in SQL
Server based on the user's input. The purpose is to
regulate which user can access which table using SQL
Server's security mechanisms.

In VS Studio "Help", under "ADO.NET, connections", in a
document "Introducti on to ADO.NET Connection Design
Tools", in the section "Configurab le Connection
Properties", they suggested the following (see below),
which clearly indicates that changing the app.config file
by the program is possible.

If I don't use the app.config file to do this, do you have
any suggestions on how to programmaticall y change the
connection string? Note that this is a Windows app (not
Web-based) and I am using Visual Studio to generate the
adapter and connection objects for every form.
Thanks, again for your help.

(Quote from VS Help)
Configurable Connection Properties

In many applications, connection information cannot be
determined at design time. For example, in an application
that will be distributed to many different customers, you
might not be able to determine at design time the
connection information (such as the name of a server, a
user name, or a password).

Connection strings are therefore often specified as
dynamic properties. Because dynamic properties are stored
in a configuration file (and not compiled into the
application binary files), they can be changed without
having to recompile the application.

A typical strategy is to specify connection properties as
dynamic properties, provide a way (such as a Windows Form
or Web Form page) for users to specify the relevant
details, and then update the configuration file. The
dynamic-property mechanism built into the .NET Framework
automatically gets the values from the configuration file
when the property is read, and updates the file when the
value is updated.
Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2598
by: TK | last post by:
What's the best way to edit web.config programmatically? I want to have an aspx page as a GUI for web admins to modify the roll-base security portion of the web.config(s) on a server. please help. TK
8
2336
by: vadim | last post by:
Hi, Is there a .Net control available that allows to write into web.config file appsettings section? The idea is to create encrypted user name and password for database connection and then use them from ASP.Net. The program that will create the encrypted entries is a simple winform app. ConfigurationSettings.appsettings allows to read...
2
1523
by: Kevin Jackson | last post by:
Is there a .NET framework call(s) or technique that allows one to programmatically find the machine.config file.
18
3763
by: Praveen Ramesh | last post by:
Hi, Is there any way to add the @Assembly reference to the aspx files programmatically from inside a custom control (when it gets dropped on to the page from the toolbox)? I have a custom control - MyControl that implements an interface in another custom assembly - InterfaceAssembly. When MyControl gets dropped on to the page and run, it...
3
9138
by: Codex Twin | last post by:
Hello apologies if this is the wrong newsgroup to be sending this to. Basically, I have an ASP.NET application that I am trying to force to use a proxy server settings. This can be done by accessing machine.config, but I do not have access to the client machine.config machine. Therefore every request made from this application must have...
3
19008
by: TC | last post by:
Hello All, I have winforms app that accesses a webservice and the WSDL is referenced dynamically. I was wondering 2 things: First, if one parses the .config file and changes the URL pointing to the WSDL, I take it that these changes would not take effect until the user closes and restarts the app, correct?
4
6781
by: Andrew | last post by:
I have ASP.NET 2.0 application. I'm running some initialization code in Application_Start() in Global.asax. If this code fails I would like to shutdown the application completely. Meaning no page, or an error page is returned to the user. I've tried HostingEnvironment.InitiateShutdown() but it's async and still returns a page to the user. ...
0
1462
by: fcaico | last post by:
I have a .NET 1.1 C# application that needs to connect to a custom web service for authentication and system access. This web service uses a custom SOAP header for security purposes. In the past this has been a non issue because I simply registered a SoapHeaderExtension in the application's App.Config file. Now, however, we have need of...
6
15293
by: Andrew Jocelyn | last post by:
Hi How do I programmatically change (read/write) the values in this app.config file at runtime? Specifically I want to change the client endpoint address but it would be nice to change other values too. I thought this is what ServiceHost is for but is seems way more complicated to use for what I'm trying to do. <system.serviceModel>...
0
7601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7913
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8117
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6274
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5496
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2099
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
931
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.