Possible Duplicate:
In C# , how can I read a connection string stored in my web.config file connection string?
I am using the SqlConnection class to connect to a sql server database. One of the constructors for this class required a connection string argument...What is the easiest way to get the required information from the web.config file....
Use ConfigurationManager.ConnectionStrings collection to read connection string from web.config.
connection string in web config
import this
using System.Configuration;
in aspx page
SqlConnection con;
string conn = ConfigurationManager.ConnectionStrings["connection string name in web config"].ConnectionString;
Try this:
First include this Namespace using System.Configuration;
and use this
string cnn = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;