Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Configuration.AppSetting is not read for WinForms Application

11 views
Skip to first unread message

Hemant Sathe

unread,
Apr 3, 2002, 12:50:24 AM4/3/02
to
Hi,
I am creating a database application in which I need to store connection
string in config file. I have tried all possible names of the config file
like Appname.exe.config, appname.config checked all spellings also but my
application is not picking up the connection string from the file.

I am using an exe and a dll. dll actually connects to the database and
config file is in exe project. Same dll is used for another WebForms
interface and the appSettings section in Web.Config works well there. But
not in WinForms application.

I am using Beta2 of VS.
Can any one suggest a solution?
Rregards
Hemant


Ryan Trudelle-Schwarz

unread,
Apr 3, 2002, 1:04:57 AM4/3/02
to
Create your own config file and object.

Steps:

1) Create an object representing all the config info you need (i usually use
properties for whatever values i need). You'll need to specify some
attributes on the properties or whatnot so take a look at the docs under
system.xml.serialization

2) Use System.Xml.Serialization.XmlSerializer to serialize it to a file
(something.config)

3) Edit that config file to your hearts content.

4) Deserialize just like you serialized.

This is basically what the Asp.Net runtime is doing when it loads an app but
it does it under the covers. There is no built in match for winforms AFAIK.

hth, Ryan

"Hemant Sathe" <hks...@hotmail.com> wrote

Kalpesh Shah

unread,
Apr 3, 2002, 2:53:06 AM4/3/02
to
Hi,

Make sure the following things

1) the config file must reside in the same directory as that of the EXE
2) the name of the config file must be myapp.exe.config - it is the same
name as that your app.exe with ".config" suffixed
3) the config file will look like

<configuration>
<appSettings>
<!-- User application and configured property settings go here.-->
<!-- Example: <add key="settingName" value="settingValue"/> -->
<add key="myconnect" value="provider=blah...blah" />
</appSettings>
</configuration>

4) In your app, use the following to get the values
System.Collections.Specialized.NameValueCollection configurationAppSettings
= System.Configuration.ConfigurationSettings.AppSettings;

MessageBox.Show(configurationAppSettings.GetValues("myconnect")[0]);


HTH

Regards
Kalpesh

"Hemant Sathe" <hks...@hotmail.com> wrote in message
news:eFKkINt2BHA.2760@tkmsftngp04...

Hemant Sathe

unread,
Apr 3, 2002, 2:20:35 AM4/3/02
to
Hi,
Thanx all. I have tried all the options given in MSDN but nothing worked.
The config file is OK.
Surprisingly renaming the file to "app.config" did the trick. All my
app.exe.config, myapp.config names did not work. Is this a problem with beta
2 or release version has the same problem?

Thanx again
Regards
Hemant

"Kalpesh Shah" <shahk...@hotmail.com> wrote in message
news:O#Joqst2BHA.2856@tkmsftngp05...

0 new messages