c# Ado.net连接池
来源:互联网 发布:怎样网络销售 编辑:程序博客网 时间:2024/05/18 01:51
Ado.net连接池使用总结:
1.第一次打开连接会创建一个连接对象。
2.当这个连接关闭时(调用Close()方法时)会将当前那个连接对象放入池中。
3.下一个连接对象,如果连接字符串与池中现有连接对象的连接字符串完全一致,则会使用池中的现有连接,而不会重新创建一个。
4.只有对象调用Close(),的时候才会放入池中,如果一个连接对象一直在使用,则下次再创建一个连接对象发现池中没有,也会再创建一个新连接对象。
在池中的连接对象,如果过一段时间没有被访问则自动销毁。
如果连接池中有对象则
cnn.open就是去池中把对象取出来
cnn.close就是把对象放到池中去
注意:当再次创建一个连接对象,如果该连接对象所使用的连接串与上次
连接对象的连接串完全一致(必须完全一致,包括大小写,空格),这时才会使用连接池
//1.启用连接池与禁用连接池为什么性能差距这么大?
//1.当启用连接池后,看似是2000次的登录与注销(连接的打开与关闭),其实只有一次打开,(当程序关闭后才会关闭)。所以高性能
//2.而禁用连接池后,则是真正的打开关闭了2000次。
//注意:当再次创建一个连接对象,如果该连接对象所使用的连接串与上次
//连接对象的连接串完全一致(必须完全一致,包括大小写,空格),这时才会使用连接池
#region 启用连接池
string constr = "Data Source=zxtiger;Initial Catalog=itcastcn;Integrated Security=True";
Stopwatch watch = new Stopwatch();
watch.Start();
//00:00:00.1383385
for (int i = 0; i < 2000; i++)
{
using (SqlConnection con = new SqlConnection(constr))
{
con.Open();
con.Close();
}
}
watch.Stop();
Console.WriteLine(watch.Elapsed);
Console.WriteLine("连接打开了又关闭了。");
Console.ReadKey();
#endregion
#region 禁用连接池后的效果
//string constr = "Data Source=zxtiger;Initial Catalog=itcastcn;Integrated Security=True;Pooling=false";
//Stopwatch watch = new Stopwatch();
//watch.Start();
////00:00:00.1383385
////00:00:03.9974913
//for (int i = 0; i < 2000; i++)
//{
// using (SqlConnection con = new SqlConnection(constr))
// {
// con.Open();
// con.Close();
// }
//}
//watch.Stop();
//Console.WriteLine(watch.Elapsed);
//Console.WriteLine("连接打开了又关闭了。");
//Console.ReadKey();
#endregion
- c# Ado.net连接池
- ADO.NET连接池
- ADO.NET:连接池
- ADO.NET连接池
- ADO.net 连接池
- ADO.Net连接池
- ado.net 连接池
- ADO.NET连接池
- ADO.NET连接池
- ADO.NET连接池
- C#使用ADO.net连接数据库
- ADO.NET连接池FAQ
- ADO.NET数据连接池
- [转]ADO.NET连接池
- ADO.NET数据连接池
- ADO.NET连接池FAQ
- ADO.NET连接池FAQ
- ADO.NET连接池FAQ
- error C2653: 'list<class CSomething*,class std::allocator<class CSomething*> >'...解决方法
- merge 字典数组 array dict
- 1-2计算天数
- IBM江月:销售为什么爱“撒谎”
- ATL 类的理解
- c# Ado.net连接池
- The Bronte Story——2、Cowan Bridge School
- 闲来无事,复习复习以前的东西---hibernate查询细节资料
- 设计模式之类之间的关系
- Bone Collector II
- 理解Proc 文件系统
- gcc命令
- sizeof操作符
- Python Tika guide