473,325 Members | 2,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

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

I am trying to read the "ConnectionString" 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"?>
<configuration>

<appParams>
<add key="ConnectionString" value="User
Id=MyID;Password=MyPW;Initial Catalog=MyDB;Server=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.Configuration.ConfigurationSettings.AppSett ings("ConnectionString"),
but that doesn't seem to work.
Nov 16 '05 #1
4 3084
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*******@discussions.microsoft.com> wrote in message
news:CD**********************************@microsof t.com...
Try: appSettings instead of <appParams><?xml version="1.0" encoding="utf-8" ?><configuration><appSettings><add key="ConnectionString"
value="YourString"/></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"?>
<configuration>
<configSections>
<section name="appParams"
type="System.Configuration.NameValueSectionHandler ,system,
Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089,
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.Configuration;
using System.Collections.Specialized;

// It's easy to retreive value1:
string s1 = ConfigurationSettings.AppSettings["key1"]; // s1 contains
"value1".

// A little more tricky for value2:
NameValueCollection nvc = ConfigurationSettings.GetConfig("appParams") as
NameValueCollection;
string s2 = nvc["key2"]; // s2 contains "value2".

Olivier DALET
---------------
"John Galt" <nf*@nospam.com> a écrit dans le message de
news:O1**************@TK2MSFTNGP10.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*******@discussions.microsoft.com> wrote in message
news:CD**********************************@microsof t.com...
Try: appSettings instead of <appParams><?xml version="1.0"

encoding="utf-8" ?><configuration><appSettings><add key="ConnectionString"
value="YourString"/></appSettings></configuration>

The rest looks good.
Good luck.


Nov 16 '05 #3
"Olivier DALET" <odalet[foo]@wanadoo.fr> wrote in message
news:eO**************@tk2msftngp13.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****************@TK2MSFTNGP12.phx.gbl...
"Olivier DALET" <odalet[foo]@wanadoo.fr> wrote in message
news:eO**************@tk2msftngp13.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
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...
1
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; ...
2
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
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...
4
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...
3
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...
0
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...
9
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...
5
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.