Search this insane blog:

Wednesday, July 30, 2008

asp.net 2.0 with c#: Accessing connection string using code behind

-- straight away connection
private void Page_Load(object sender, EventArgs e)
{
string connectionInfo = ConfigurationSettings.AppSettings["ConnectionInfo"];
using(SqlConnection connection = new SqlConnection(connectionInfo))
{
connection.Open();

// perform work with connection

}
}
--- to encapsulate a connection stored in your web.config
private void Page_Load(object sender, EventArgs e)
{
string connectionInfo = ConfigurationSettings.AppSettings["ConnectionInfo"];
using(SqlConnection connection = new SqlConnection(connectionInfo))
{
connection.Open();

// perform work with connection

}
}

----------------------------
private void Page_Load(object sender, EventArgs e)
{
string connectionInfo = ConfigurationSettings.AppSettings["ConnectionInfo"];
using(SqlConnection connection = new SqlConnection(connectionInfo))
{
connection.Open();

// perform work with connection

}
}



you can read the details at odetocode...
source: http://www.odetocode.com/Articles/345.aspx

No comments:

Post a Comment