473,772 Members | 3,603 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I read a specific value from a config file?

I am trying to read the "ConnectionStri ng" value from my app.exe.config
file, but am not sure of the format to do this.

It is of the form:

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

<appParams>
<add key="Connection String" value="User
Id=MyID;Passwor d=MyPW;Initial Catalog=MyDB;Se rver=d-sql;" />
</appParams>

etc.

</configuration>

In particular, I am interesting in getting the "Server=d-sql" info.

It seems like is should be something like
System.Configur ation.Configura tionSettings.Ap pSettings("Conn ectionString"),
but that doesn't seem to work.
Nov 16 '05 #1
4 3138
The problem is that this is being used by Microsoft's Data Application
Block. I need the connection screen info to display which system the
application is pointing to (Development, Production, etc.)

"Morris" <an*******@disc ussions.microso ft.com> wrote in message
news:CD******** *************** ***********@mic rosoft.com...
Try: appSettings instead of <appParams><?xm l version="1.0" encoding="utf-8" ?><configuratio n><appSettings> <add key="Connection String"
value="YourStri ng"/></appSettings></configuration>
The rest looks good.
Good luck.

Nov 16 '05 #2
Are you really sure the tag isn't appSettings ?... For appParams isn't part
of standard .net config files:
If you want to use appParams, you've got to declare it inthe xml and then
the way you access it isn't as simple as for appSettings:

1 - sample App.exe.config:
<?xml version="1.0" encoding="utf-8"?>
<configuratio n>
<configSections >
<section name="appParams "
type="System.Co nfiguration.Nam eValueSectionHa ndler,system,
Version=1.0.330 0.0, Culture=neutral , PublicKeyToken= b77a5c561934e08 9,
Custom=null"/>
</configSections>
<appSettings>
<add key="key1" value="value1" />
</appSettings>
<appParams>
<add key="key2" value="value2" />
</appParams>
</configuration>

You'll notice that because appParams isn't standard, you have to declare it
in the configSections part.

2 - Accessing values (in C#) :

using System.Configur ation;
using System.Collecti ons.Specialized ;

// It's easy to retreive value1:
string s1 = ConfigurationSe ttings.AppSetti ngs["key1"]; // s1 contains
"value1".

// A little more tricky for value2:
NameValueCollec tion nvc = ConfigurationSe ttings.GetConfi g("appParams" ) as
NameValueCollec tion;
string s2 = nvc["key2"]; // s2 contains "value2".

Olivier DALET
---------------
"John Galt" <nf*@nospam.com > a écrit dans le message de
news:O1******** ******@TK2MSFTN GP10.phx.gbl...
The problem is that this is being used by Microsoft's Data Application
Block. I need the connection screen info to display which system the
application is pointing to (Development, Production, etc.)

"Morris" <an*******@disc ussions.microso ft.com> wrote in message
news:CD******** *************** ***********@mic rosoft.com...
Try: appSettings instead of <appParams><?xm l version="1.0"

encoding="utf-8" ?><configuratio n><appSettings> <add key="Connection String"
value="YourStri ng"/></appSettings></configuration>

The rest looks good.
Good luck.


Nov 16 '05 #3
"Olivier DALET" <odalet[foo]@wanadoo.fr> wrote in message
news:eO******** ******@tk2msftn gp13.phx.gbl...
Are you really sure the tag isn't appSettings ?... For appParams isn't part of standard .net config files:
If you want to use appParams, you've got to declare it inthe xml and then
the way you access it isn't as simple as for appSettings:


Yes. This is the format used by the Application Block.

Not sure why it works, but it does.
Nov 16 '05 #4
What application block are you talking about: I've just downloaded versions
1 and 2 of MS Data Application Block, and I've seen nothing concerning
configuration reading, neither appParams sections...

I've downloaded these blocks at
http://www.microsoft.com/downloads/d...8-2891102590AD
(V1)
and
http://www.microsoft.com/downloads/d...displaylang=en
(V2)

could you tell which block you are using and provide a link to it?

Olivier DALET
---------------
"John Galt" <nf*@nospam.com > a écrit dans le message de
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
"Olivier DALET" <odalet[foo]@wanadoo.fr> wrote in message
news:eO******** ******@tk2msftn gp13.phx.gbl...
Are you really sure the tag isn't appSettings ?... For appParams isn't

part
of standard .net config files:
If you want to use appParams, you've got to declare it inthe xml and then the way you access it isn't as simple as for appSettings:


Yes. This is the format used by the Application Block.

Not sure why it works, but it does.

Nov 16 '05 #5

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

Similar topics

2
3316
by: MrFile | last post by:
I added an app.config file to my application. (c#.net component dll) <?xml version="1.0" encoding="utf-8"?> <configuration> <appSettings> <add key="username" value="xx" /> <add key="password" value="xx" /> </appSettings> </configuration>
1
5360
by: vkrasner | last post by:
It works with VS2003 and does not in VS2005: in VS2003 : string sMyvalue = ConfigurationSettings.AppSettings; in VS2005 (does not work!!) string sMyvalue = ConfigurationManager.AppSettings; Anybody able to give me idea how-to read by C# element which I add to the machine.config into the new single section?
2
3091
by: Grey | last post by:
I want to create one element in web.config file, but i don't know how.. Please teach me how to create and read the element from web.config. Million Thanks.
4
1809
by: brent | last post by:
Currently our application is reading from the web.config, and retrieves a section, "softwareRequirements". Because the section will begin to grow dramatically, I'd like to place it in the SQL database instead. I've imported the values, and am retrieving them as FOR XML AUTO in the stored proc to mimic the structure in the web.config. I'm confused now - what data type is being returned by...
4
2312
by: klynn | last post by:
Hi: I'm having problems reading a Microsoft Access file from my ASP.Net app on a Windows Server 2003 machine. The error message: The Microsoft database engine cannot open the file, <my_file>. It is already opened exclusively by another user, or you need permission to view its data. I've read some info about this (microsoft support article q316675) but I'm still confused on what to do?
3
15967
by: Brett Romero | last post by:
I'd like to use some of the techniques discussed here for reading a config file in .NET 2.0: http://msdn.microsoft.com/msdnmag/issues/06/06/ConfigureThis/default.aspx Here's my app.config content: <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections>
0
1367
by: hazz | last post by:
I want to load Service.exe.config into a DataGrid, change the timer interval value from 10000 to 555555, then update the original exe.config. The code below shows the code at step 1 and 2 before creating ServiceNew.exe.config below. The initial line, '<?xml version="1.0" encoding="utf-8" ?' is missing and the nodes are not hiearchical with indentation from the root to the innermost nodes as the original config file. How can I add this...
9
4273
by: =?Utf-8?B?TWlrZQ==?= | last post by:
Hi. Is it programatically possible in VB.NET to read the contents of web.config's <customErrorselement? I looked at using ConfigurationSettings.AppSettings, but that doesn't work. I need to read the value of redirect from the error statusCode 404. My web.config looks like this: <customErrors mode="RemoteOnly" defaultRedirect="Error.aspx"> <error statusCode="404" redirect="Error404.aspx" /> </customErrors>
5
1652
by: CSharp-Jay | last post by:
So I have been programming in C# on a personal level as of lately, and am curious about something. Lately I have been experimenting around with file create/write, etc. I can open and read the whole file, but how do I read specific words into my program? Like for example, I have an ini file that my program writes to and needs to read from to know user specific settings. But I need to know each line individually and what the value is so...
0
9620
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10104
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8934
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6715
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2850
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.