-- 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