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)

Re: Getting the connection string from the App.Config File (2005) by Herfried

Herfried
Fri Aug 18 11:46:08 CDT 2006

"jonefer" <jonefer@discussions.microsoft.com> schrieb:
>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'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Re: Getting the connection string from the App.Config File (2005) by jonefer

jonefer
Fri Aug 18 13:00:01 CDT 2006

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)


"Herfried K. Wagner [MVP]" wrote:

> "jonefer" <jonefer@discussions.microsoft.com> schrieb:
> >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'.
>
> --
> M S Herfried K. Wagner
> M V P <URL:http://dotnet.mvps.org/>
> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
>

Re: Getting the connection string from the App.Config File (2005) by Herfried

Herfried
Fri Aug 18 13:14:51 CDT 2006

"jonefer" <jonefer@discussions.microsoft.com> schrieb:
> '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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


Re: Getting the connection string from the App.Config File (2005) by jonefer

jonefer
Fri Aug 18 15:16:02 CDT 2006

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

"Herfried K. Wagner [MVP]" wrote:

> "jonefer" <jonefer@discussions.microsoft.com> schrieb:
> > '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.
>
> --
> M S Herfried K. Wagner
> M V P <URL:http://dotnet.mvps.org/>
> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
>
>

Re: Getting the connection string from the App.Config File (2005) by Jim

Jim
Mon Aug 21 09:12:07 CDT 2006

> 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