先建立一个空的web窗体
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Diagnostics;
namespace _11_26数据库连接内容1
{
public partial class ConnectionPool : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string constr = "data source=.;initial catalog=最终的练习;user id=sa;password=admin";
Stopwatch watch = new Stopwatch();
watch.Start();
for (int i = 0; i < 2000; i++)
{
using (SqlConnection con = new SqlConnection(constr))
{
con.Open();
con.Close();
}
}
watch.Stop();
Response.Write(watch.Elapsed);
Response.Write("链接打开又关闭了!");
}
}
}