连接池

来源:互联网 发布:曼哈顿软件 编辑:程序博客网 时间:2024/05/21 05:40

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 ADO_dataReader
{
    public partial class connectionPool : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
             string constr = "data source=PC-20120907SDQU;initial catalog=School;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("连接打开又关闭了!");
        }
    }
}