Getting the connection string from the App.Config File (2005)

G

Guest

I guess the following only works for Web Projects...

Imports System.Data.SqlClient
Imports System.Configuration

Dim sCodaCon As String =
System.Configuration.ConfigurationManager.AppSettings("MyCnn")

What is the equivalent for retrieving the ConnectionString from the
App.Config file?
(Visual Studio 2005)
 
H

Herfried K. Wagner [MVP]

jonefer said:
I guess the following only works for Web Projects...

Imports System.Data.SqlClient
Imports System.Configuration

Dim sCodaCon As String =
System.Configuration.ConfigurationManager.AppSettings("MyCnn")

What is the equivalent for retrieving the ConnectionString from the
App.Config file?

'My.Settings'.
 
G

Guest

but the entire line:

'System.Configuration.ConfigurationManager'

Doesn't work - says ConfigurationManager isn't under Configuration (this is
only in a Windows Project, WebProject has ConfigurationManager)
 
H

Herfried K. Wagner [MVP]

jonefer said:
'System.Configuration.ConfigurationManager'

Doesn't work - says ConfigurationManager isn't under Configuration (this
is
only in a Windows Project, WebProject has ConfigurationManager)

You don't need this code at all. 'My.Settings.*' should be sufficient to
access the connection string.
 
G

Guest

Thank you. You wouldn't believe how difficult it was to find that very
simple yet so important piece of information.
 
J

Jim Wooley

I guess the following only works for Web Projects...
Imports System.Data.SqlClient
Imports System.Configuration
Dim sCodaCon As String =
System.Configuration.ConfigurationManager.AppSettings("MyCnn")

What is the equivalent for retrieving the ConnectionString from the
App.Config file?
(Visual Studio 2005)

You need to add a reference to System.ConfigurationManager. It is not there
by default. Once you have it, everything should work the same.

Jim Wooley
http://devauthority.com/blogs/jwooley/default.asp
 

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