Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / August 2006

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jonefer - 18 Aug 2006 17:10 GMT
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)
Herfried K. Wagner [MVP] - 18 Aug 2006 17:46 GMT
"jonefer" <jonefer@discussions.microsoft.com> schrieb:
>I guess the following only works for Web Projects...
>
[quoted text clipped - 6 lines]
> What is the equivalent for retrieving the ConnectionString from the
> App.Config file?

'My.Settings'.

Signature

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

jonefer - 18 Aug 2006 19:00 GMT
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" <jonefer@discussions.microsoft.com> schrieb:
> >I guess the following only works for Web Projects...
[quoted text clipped - 9 lines]
>
> 'My.Settings'.
Herfried K. Wagner [MVP] - 18 Aug 2006 19:14 GMT
"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.

Signature

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

jonefer - 18 Aug 2006 21:16 GMT
Thank you.  You wouldn't believe how difficult it was to find that very
simple yet so important piece of information.

> "jonefer" <jonefer@discussions.microsoft.com> schrieb:
> > 'System.Configuration.ConfigurationManager'
[quoted text clipped - 5 lines]
> You don't need this code at all.  'My.Settings.*' should be sufficient to
> access the connection string.
Jim Wooley - 21 Aug 2006 15:12 GMT
> I guess the following only works for Web Projects...
>
[quoted text clipped - 6 lines]
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.