Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I get the connectionstring from the web.config file

Status
Not open for further replies.

joelwenzel

Programmer
Jun 28, 2002
448
I know in the aspx source code, I can access the connection strings using "<%$ ConnectionStrings:ConnString%>"

However, I want to access it from the .vb file. How do I do this? CurrentlyI am using the appsettings as a quick fix

ConfigurationSettings.AppSettings("myConnectionString")
 
Figured it out...

System.Configuration.ConfigurationManager.ConnectionStrings("myConnectionString").ConnectionString
 
To shorten your code you can do this:
Code:
Imports System.Configuration.ConfigurationManager

Then you only need this:
Code:
<YourVariable> = ConnectionStrings("myConnectionString").ConnectionString

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top