010_.Net 连接池
SourceCode:
protected void btnOK_Click(object sender, System.EventArgs e)
{
string strConUnusePool = "server=(local);database=mydatabase;uid=sa;pwd=111;pooling=false";
string strConusePool = "server=(local);database=mydatabase;uid=sa;pwd=111;pooling=true";
int nConNum = int.Parse(tbNum.Text);
//计算不使用连接池创建连接的时间
DateTime dtStart = DateTime.Now;
for(int i=1;i<=nConNum;i++)
{
SqlConnection con = new SqlConnection(strConUnusePool);
con.Open();
con.Close();
}
DateTime dtEnd = DateTime.Now;
TimeSpan ts = dtEnd-dtStart;
lbUnuse.Text = ts.Milliseconds.ToString();
//计算使用连接池的时间
dtStart = DateTime.Now;
for(int i=1;i<=nConNum;i++)
{
SqlConnection con = new SqlConnection(strConusePool);
con.Open();
con.Close();
}
dtEnd = DateTime.Now;
ts = dtEnd-dtStart;
lbUse.Text = ts.Milliseconds.ToString();
}