473,503 Members | 2,322 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Write to config file

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<connectionStrings>

<add name="DataBaseConnection"
connectionString="server=localhost;database=SalesD B;User
ID=sales1;Password=sales1"/>

</connectionStrings>
</configuration>

This is the code I use to read the whole string value:

string sConn =
config.ConnectionStrings.ConnectionStrings["DataBaseConnection"].ToString();

I want to do the followings:

1) retrieve each value of the "server", "database", "User" and "Password"

2)write back to configuration file:

server=localhost;database=SalesTestDB;User ID=salesTest1;Password=salesTest1
Sep 7 '06 #1
2 2897
Hi Alan,
You will have to either use xml parser or write your own logic to read
the elements inside the configuration tags.
Same is true for writing back the configuration settings. I havent
found any way by which C# will allow you to write back to the
configuration file. We are using XmlDocument to read and write to
configuration file of our application.

-Sac

Alan T wrote:
<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<connectionStrings>

<add name="DataBaseConnection"
connectionString="server=localhost;database=SalesD B;User
ID=sales1;Password=sales1"/>

</connectionStrings>
</configuration>

This is the code I use to read the whole string value:

string sConn =
config.ConnectionStrings.ConnectionStrings["DataBaseConnection"].ToString();

I want to do the followings:

1) retrieve each value of the "server", "database", "User" and "Password"

2)write back to configuration file:

server=localhost;database=SalesTestDB;User ID=salesTest1;Password=salesTest1
Sep 7 '06 #2
If your using .net 2 you've got the ConnectionStringSettings and
ConnectionStringsSection types which provider programmatic access without
the need to handle XML.

As for parsing out values from a connection string .net 2 also includes
connection string builder classes which you can supply a connection string
in the constructor (or not) and then access individual values from
properties.

OracleConnectionStringBuilder o = new OracleConnectionStringBuilder( "Data
Source=emp;password=scott;user id=tiger" );

Console.WriteLine( o.UserID );
Console.WriteLine( o.Password );

Although this was done using ODP.NET, I believe similiar classes are
available for all database types included with ADO.NET.

HTH

Glenn

<sk*******@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Hi Alan,
You will have to either use xml parser or write your own logic to read
the elements inside the configuration tags.
Same is true for writing back the configuration settings. I havent
found any way by which C# will allow you to write back to the
configuration file. We are using XmlDocument to read and write to
configuration file of our application.

-Sac

Alan T wrote:
><?xml version="1.0" encoding="utf-8" ?>

<configuration>

<connectionStrings>

<add name="DataBaseConnection"
connectionString="server=localhost;database=Sales DB;User
ID=sales1;Password=sales1"/>

</connectionStrings>
</configuration>

This is the code I use to read the whole string value:

string sConn =
config.ConnectionStrings.ConnectionStrings["DataBaseConnection"].ToString();

I want to do the followings:

1) retrieve each value of the "server", "database", "User" and "Password"

2)write back to configuration file:

server=localhost;database=SalesTestDB;User
ID=salesTest1;Password=salesTest1

Sep 7 '06 #3

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

Similar topics

2
3039
by: lawrence | last post by:
I've been bad about documentation so far but I'm going to try to be better. I've mostly worked alone so I'm the only one, so far, who's suffered from my bad habits. But I'd like other programmers...
33
3445
by: Nick Evans | last post by:
Hello there, I have been on and off learning to code (with python being the second language I have worked on after a bit of BASIC). What I really want to know is, if you are going to actually...
0
1372
by: Joan Bos | last post by:
Hi, Is there somewhere on the Internet a description of what a .NET application config file should contain? For our application, I have to write passwords encrypted in a config file. The...
2
4551
by: Shaun Ram | last post by:
Hi I have this constraint. A help would be greatly apprecitated. I have this Config file. <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <sectionGroup name="ITASCA">...
9
8265
by: ALI-R | last post by:
Hi,, I have two questions : 1) Is it mandatory that config file of a desktop application must be App.config 2) Is it possible to update config file in your code?? thanks for your help. ALI
4
1663
by: feng | last post by:
..Net's .config file is supposed to replace the .ini files. That's all fine if all I need is to read from it. But what if I need both read and write? With .ini file, I can do that very easily with...
3
5291
by: Agnes | last post by:
Can I write a file like config.ini which store the server-name, userid & password, So, my application can read the config.ini file and get the server - name, Does my concept is correct ? If...
4
1679
by: Jeff smith | last post by:
I am reading the value from config file using the below statement. System.Configuration.ConfigurationSettings.AppSettings("MY_DATA") How to write data back to the same location? I am using...
1
1725
by: Lialie | last post by:
Hello,all I found it easy to read configures from a config file. But how can I set a special value to an item or write it into the original file? I have tried this: import ConfigParser config...
4
1833
by: apriebe47 | last post by:
Alright, I realize this is probably very basic to be posted on this newsgroup but I cannot figure out what is causing my problem. Here is the code I am using below: from getpass import getpass ...
0
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
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...
0
7357
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...
1
7012
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5598
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,...
0
4690
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...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3171
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
402
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...

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.