How to Read Connection Strings from the app.config File?

isawa

Active member
Joined
Oct 3, 2005
Messages
25
Programming Experience
Beginner
How to Read Connection Strings from the app.config File?
VS 2005 :confused:
 
connection strings can be handled just like any other string

depending on how the config file is written, i use the StreamReader class for reading text files if it's an xml file then i use a dataset for ease of use

but once you've read in the info simply assign the string to the database connection
 
There's no need for you to do the reading. If you create the connection in the design window then you can use the Properties window to automatically save and retrieve the ConnectionString through the ApplicationSettings. If you haven't created the connection in the designer you can still use settings. You go to the Settings tab of the project properties, then save your connection string as a String. Whatever name you use for the setting then becomes a property of the My.Settings object, so at run time you can just do this:
VB.NET:
myConnection.ConnectionString = My.Settings.MyConnectionString
 
Back
Top