How to get the connection string from web.config?


Truly this is as easy as pie

in web.config file add a node like this in the <appsettings> node

<add key=”dbConnection” value=”
Server=YOUR_SERVER_NAME;User ID=USER_NAME_DB;Password=YOUR_PASSWORD;Initial Catalog=DBNAME;”/>

Now in the code file add the following line whereever u want to get the connection String

string conStr = ConfigurationManager.AppSettings[“dbConnection”];

and then do whatever you wanna do with that!

Advertisements

Author: Imran Akram

A .NET/SharePoint Consultant and a political enthusiast who believes in putting the feet of the elected and/or unelected officials to fire in order to get good governance.

1 thought on “How to get the connection string from web.config?”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s