Using the .Config file in my application

G

Guest

Hi
I have the following in my .config fil

<?xml version="1.0" encoding="utf-8" ?><configuration><appsetting><add key="ConnectString" value=""DSN=progress;UID=;PWD=" /></appsetting></configuration

I have the following code in my applicatio

Dim odbcConn As Odbc.OdbcConnection = New Odbc.OdbcConnection(Configuration.ConfigurationSettings.AppSettings("ConnectString")

odbcConn.Open(

MsgBox((odbcConn.State).ToString

When I run this I get the following error

An unhandled exception of type 'System.Configuration.ConfigurationException' occurred in system.dl

Additional information: Unrecognized configuration section appsettin

Any ideas?
 
G

Graeme Malcolm \(Content Master Ltd.\)

<appsetting> should be <appSettings> (note plural and camelCase)

Cheers,
Graeme

--
Graeme Malcolm
Principal Technologist
Content Master Ltd.
www.contentmaster.com


Chris said:
Hi,
I have the following in my .config file

<?xml version="1.0" encoding="utf-8" ?><configuration><appsetting><add
key="ConnectString" value=""DSN=progress;UID=;PWD="
/> said:
I have the following code in my application

Dim odbcConn As Odbc.OdbcConnection = New Odbc.OdbcConnection(Configuration.ConfigurationSettings.AppSettings("Connect
String"))


odbcConn.Open()


MsgBox((odbcConn.State).ToString)


When I run this I get the following error:

An unhandled exception of type
'System.Configuration.ConfigurationException' occurred in system.dll
 
G

Greg

invalid xml

Chris said:
Hi,
I have the following in my .config file

<?xml version="1.0" encoding="utf-8" ?><configuration><appsetting><add
key="ConnectString" value=""DSN=progress;UID=;PWD="
/> said:
I have the following code in my application

Dim odbcConn As Odbc.OdbcConnection = New Odbc.OdbcConnection(Configuration.ConfigurationSettings.AppSettings("Connect
String"))


odbcConn.Open()


MsgBox((odbcConn.State).ToString)


When I run this I get the following error:

An unhandled exception of type
'System.Configuration.ConfigurationException' occurred in system.dll
 
W

William Ryan eMVP

Chris:

You have an extra quote mark after value...you only need one.

Here's a copy of one I use all the time.. Just plug in the values

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="connectString" value="packet size=4096;integrated
security=SSPI;data source=xxxxxxx;persist security info=False;initial
catalog=xxxxxx" />
</appSettings>
</configuration>

I also have a discussion of this in the first part of my article here
http://www.knowdotnet.com/articles/ddl.html

HTH,

Bill
Chris said:
Hi,
I have the following in my .config file

<?xml version="1.0" encoding="utf-8" ?><configuration><appsetting><add
key="ConnectString" value=""DSN=progress;UID=;PWD="
/> said:
I have the following code in my application

Dim odbcConn As Odbc.OdbcConnection = New Odbc.OdbcConnection(Configuration.ConfigurationSettings.AppSettings("Connect
String"))


odbcConn.Open()


MsgBox((odbcConn.State).ToString)


When I run this I get the following error:

An unhandled exception of type
'System.Configuration.ConfigurationException' occurred in system.dll
 
W

William Ryan eMVP

Chris:

I just noticed Graeme's comment and that's definitely an issue too. I think
the extra quote is causing a problem, but the appsettings issue will give
you grief too.


Chris said:
Hi,
I have the following in my .config file

<?xml version="1.0" encoding="utf-8" ?><configuration><appsetting><add
key="ConnectString" value=""DSN=progress;UID=;PWD="
/> said:
I have the following code in my application

Dim odbcConn As Odbc.OdbcConnection = New Odbc.OdbcConnection(Configuration.ConfigurationSettings.AppSettings("Connect
String"))


odbcConn.Open()


MsgBox((odbcConn.State).ToString)


When I run this I get the following error:

An unhandled exception of type
'System.Configuration.ConfigurationException' occurred in system.dll
 
W

William Ryan eMVP

Nice catch.. I guess Neil C isn't the only code wizard over there at Content
Master ;-)
 
J

JC

Hi Siobhan,

What is the name of your .Config file?

When using Visual Studio, the file must be called app.config. When you build
the solution, it will be and copied to the bin folder and renamed to
MyProgram.exe.config (where MyProgram is the name of your program). When it
is running, it is the renamed copy in the bin folder that is being used. If
the originial file is not called app.config, VS doesn't realize it is the
proper config file and it won't be copied and therefore won't be used.

The contents of your file looks okay.

- Jarod Chay
Automated Design Systems


Siobhan said:
Hi - can anyone please help this is driving me up the wall!! I have a config file:

<?xml version="1.0" encoding="utf-8"?><configuration><appSettings>
<add key="connectString"
value="server=DEV1-SMCT\NIIR;database=DBName;uid=username;password=password"
/> said:
(In final release I won't have passwords in this!!)

And when I load my first form I try and retrieve the value using

str_Connection = ConfigurationSettings.AppSettings("connectString")

And every time this returns Nothing

I also tried the line str_Connection =
ConfigurationSettings.AppSettings.Item("connectString").ToString but just
gives an error because the object is nothing!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top