Opening and Reading a Web.Config file for connectionstring

BlakeMcKenna

Active member
Joined
Oct 27, 2008
Messages
38
Programming Experience
10+
Can anyone show me a code snippent on how to open and read a Web.Config file and locate the connectionstring?

Thanks,
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,295
Location
Sydney, Australia
Programming Experience
10+
Do you mean a web site opening its own config file or a program opening a config file for any web site? If it's the former, the WebConfigurationManager class has an AppSettings property and a ConnectionStrings property, both of which can be indexed by key to get the corresponding value. If it's the latter, the same class can be used to open a specific config file and return a Configuration object, which also has the two aforementioned properties.
 

BlakeMcKenna

Active member
Joined
Oct 27, 2008
Messages
38
Programming Experience
10+
I have a web application that is needs to go to the Web.Config for the connection string. Do you have a code example in VB.Net?
 
Top Bottom