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

  • Thread starter Thread starter Guest
  • Start date Start date
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)
 
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'.
 
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)
 
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.
 
Thank you. You wouldn't believe how difficult it was to find that very
simple yet so important piece of information.
 
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
 
Back
Top