[杂]SQL Server 之 Understanding Connection Pooling and Transactions
A SqlConnection consists of two parts: the public instance that your code interacts with (the outer connection) and a hidden connection that represents an actual server connection (the inner connection).
When you call the Open method on the outer connection, the connection manager looks for a free inner connection from the pool that is associated with the transaction. It will create a new inner connection if one does not exist. When the Close method is called on the outer connection, it returns the inner connection to the pool, where the connection State is reset to ensure a clean slate when it is reused from the pool. SQL Server does not distinguish between the outer and inner connections, so only one outer connection can be used with one inner connection at a time.
When a pooled connection is reset, cursors are closed, options are set back to defaults, the database context is switched back to the one specified in the connection string, and all outstanding local transactions are rolled back. This behavior provides a known starting state every time that you open a connection from the pool. It also prevents you from reusing the inner connection until the local transaction finishes. When you close the transaction's outer connection, the inner connection is set aside pending a commit or rollback request from the transaction manager. When you open a new outer connection while the inner connection is still active, the pool will be empty, and a new inner connection is created. The local transaction manager will then detect that two different resources are trying to enlist in the same transaction. Because SQL Server connections cannot share in local transactions, the transaction manager must promote the transaction to a full distributed transaction.
以上来自于MSDN: http://msdn.microsoft.com/en-us/library/ms172070(v=vs.90).aspx
简言之,"SqlConnection " 由两部份组成:外部可操作实例和内部隐藏的连接。
当调用外部连接的open方法的时候,连接管理类寻找一个内部连接去关联。当找不到对应的内部连接时,将会创建一个内部连接实例。
当调用外部连接的close方法的时候,连接管理类将内部连接状态标记为等待提交或者回滚。一直等待提交或者回滚以后,将这个内部连接扔会到连接池,然后重置内部连接以备用。
这就是为什么命名SqlConnection都已经被close,相关的Transactions仍然能够被回滚,因为真正的连接并没有断开。

[杂]SQL Server 之 Understanding Connection Pooling and Transactions的更多相关文章
- [杂]SQL Server 之 Service Broker
由于某些原因,我们的缓存依赖于数据库,而数据库反向通知需要依赖和使用ServiceBroker, 由于Deploy的人往往不是很清楚这个SB需要如何部署,特此记录. 判断数据库是否启用了Service ...
- [杂]SQL Server 之命名管道连接
命名管道是通过进程间通信(IPC)机制实现通信.具体来说,命名管道建立在服务器的IPC$共享基础上,通过IPC$共享来进行通信. SQL Server命名管道 SQL Server 首先在服务器上创建 ...
- 微软Microsoft SQL server 之 MDS connection问题
微软的MDS和DQS使用面大概还不太广的两个新产品,之前有说道DQS的system.web的register的问题,MDS的问题就经常会碰到链接的问题,当你的用户在Excel中经常都会发生以下问题的时 ...
- .net core 连接sql server 时提示Connection Timeout Expired
.net core开发环境是ubuntu LINUX, 在ubuntu 上 telnet 数据库IP 端口是通的. SQL SERVER 是2008 ,未打SP补丁. 打完 SQL SERVER 2 ...
- Understanding how SQL Server executes a query
https://www.codeproject.com/Articles/630346/Understanding-how-SQL-Server-executes-a-query https://ww ...
- ADO.NET Connection Pooling at a Glance
ADO.NET Connection Pooling at a Glance Establishing a connection with a database server is a hefty a ...
- Migrating Oracle on UNIX to SQL Server on Windows
Appendices Published: April 27, 2005 On This Page Appendix A: SQL Server for Oracle Professionals Ap ...
- JDBC连接SQL Server代码模板
* JDBC连接SQL Server数据库 代码模板* Connection: 连接数据库并担任传送数据的任务:* Statement : 执行SQL语句:* Re ...
- ORACLE透明网关访问SQL Server配置总结
透明网关概念 ORACLE透明网关(Oracle Transparent Gateway)可以解决ORACLE数据库和非ORACLE数据库交互数据的需求.在一个异构的分布式环境中,通过ORACLE ...
随机推荐
- 旋转屏幕时,假如自定义的xib大小变了,可能是这个属性没有修改
虽然xib内部启用了自动布局,但是当xib放入外界,xib自身的autoresizing是存在的
- Nonove js timer 计时器
<html> <head> <title> Nonove js timer 计时器 </title> </head> <body> ...
- iOS-(kCFStreamErrorDomainSSL, -9802)
kCFStreamErrorDomainSSL, -9802 我是微博授权时get页面时候碰到的 其实就是http安全问题 在info.plist里添加并设置Allow Arbitrary Loads ...
- 如何调试R程序(转载)
R语言的调试重要性不言而喻,这段时间准备改进一个R的包,但由于接触R时间不长,中间的很多东西不懂,需要重新打包调试,以对里面的很多程序有深入了解,下面从几个方面分享一下我的收获. 1.准备工作 a)R ...
- Ajax技术详解
Ajax技术:Ajax描述了一种主要使用脚本(JS)操纵HTTP的web应用架构,它的主要特点是使用脚本操纵HTTP和web服务器进行数据交换,不会导致页面重载.Ajax的核心是JS的XMLHttpR ...
- meta中的viewport指令
网页手机wap2.0网页的head里加入下面这条元标签,在iPhone的浏览器中页面将以原始大小显示,并不允许缩放. <meta name="viewport" conten ...
- SGU 180 Inversions(离散化 + 线段树求逆序对)
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=180 解题报告:一个裸的求逆序对的题,离散化+线段树,也可以用离散化+树状数组.因为 ...
- NGUI之UICamera控制触摸,鼠标事件
http://blog.csdn.net/onerain88/article/details/18963539 . UICamera 功能介绍 主要包括UI事件的监听,分发,覆盖范围为此Camera渲 ...
- 即时聊天 / XMPP
MQTT是第二个即时聊天协议(了解) 5.即时通讯 即时通讯网上有第三方的解决方案,比如环信,融云等.我们是自己搭的xmpp服务器,服务器使用的tigase,之前写过相关的博客,自己去年也做了对应的w ...
- Sort List
采用归并排序,通过定义快.慢两个指针来找到中点,再采用之前的排序算法进行归并. ListNode *listSort(ListNode *head) { //定义快慢指针,找到链表中心 ListNod ...