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的更多相关文章

  1. [杂]SQL Server 之 Service Broker

    由于某些原因,我们的缓存依赖于数据库,而数据库反向通知需要依赖和使用ServiceBroker, 由于Deploy的人往往不是很清楚这个SB需要如何部署,特此记录. 判断数据库是否启用了Service ...

  2. [杂]SQL Server 之命名管道连接

    命名管道是通过进程间通信(IPC)机制实现通信.具体来说,命名管道建立在服务器的IPC$共享基础上,通过IPC$共享来进行通信. SQL Server命名管道 SQL Server 首先在服务器上创建 ...

  3. 微软Microsoft SQL server 之 MDS connection问题

    微软的MDS和DQS使用面大概还不太广的两个新产品,之前有说道DQS的system.web的register的问题,MDS的问题就经常会碰到链接的问题,当你的用户在Excel中经常都会发生以下问题的时 ...

  4. .net core 连接sql server 时提示Connection Timeout Expired

    .net core开发环境是ubuntu LINUX, 在ubuntu 上 telnet 数据库IP 端口是通的. SQL SERVER 是2008 ,未打SP补丁. 打完 SQL SERVER  2 ...

  5. Understanding how SQL Server executes a query

    https://www.codeproject.com/Articles/630346/Understanding-how-SQL-Server-executes-a-query https://ww ...

  6. 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 ...

  7. 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 ...

  8. JDBC连接SQL Server代码模板

    *                  JDBC连接SQL Server数据库 代码模板* Connection: 连接数据库并担任传送数据的任务:* Statement :  执行SQL语句:* Re ...

  9. ORACLE透明网关访问SQL Server配置总结

      透明网关概念 ORACLE透明网关(Oracle Transparent Gateway)可以解决ORACLE数据库和非ORACLE数据库交互数据的需求.在一个异构的分布式环境中,通过ORACLE ...

随机推荐

  1. 去除DedeCms 5.7后台版权广告链接的方法

    织梦DedeCms 5.7后台有很多的织梦官方的广告链接,下面我们来将这些广告去掉吧. 一.去处后台登陆页login.php广告链. 1.找到登录界面模板文件/dede/templets/login. ...

  2. Color Space

    色域(Color Space),又被称为色彩空间,它代表了一个色彩影像所能表现的色彩具体情况.我们经常用到的色彩空间主要有RGB.CMYK.Lab等,而RGB色彩 空间又有AdobeRGB.Apple ...

  3. SQL防注入程序

    1.在Global.asax.cs中写入: protected void Application_BeginRequest(Object sender,EventArgs e){      SqlIn ...

  4. 下载安装resin-3.X服务器并配置到myeclipse

    前提是先安装jdk,具体自己安装. 1.到resin官网http://www.caucho.com/download/下载相应压缩包,比如resin-3.2.0.zip 2.解压下载的resin-3. ...

  5. asp.net缓存(转)

    转自:http://www.cnblogs.com/knowledgesea/archive/2012/06/20/2536603.html 一.缓存概念,缓存的好处.类型.            缓 ...

  6. js返回上一步

    用按钮来链接返回上一步. <input type ="button" value="返回上一步" onclick="javascript:his ...

  7. HDU4870_Rating_双号从零单排_高斯消元求期望

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4870 原题: Rating Time Limit: 10000/5000 MS (Java/Other ...

  8. css的一些小技巧!页面视觉差!

    相当长的一段时间,现在网站与所谓的“视差”效果一直很受欢迎. 万一你没有听说过这种效果,不同的图像,在不同的方向移动或层主要包括.这导致了一个很好的光学效应,使参观者的注意. 在网页设计中,为了实现这 ...

  9. C# JavascriptSerializer与匿名对象打造Json的完美工具

    一:背景 在web项目中经常需要生成json数据,返回给前端ajax. 无论是ashx,还是WebMethod,可以人工的用字符串去拼接,最终得到json数据. 有没有更好的方法呢?我个人推荐使用Ja ...

  10. CSS简写指南

    高效的css写法中的一条就是使用简写.通过简写可以让你的CSS文件更小,更易读.而了解CSS属性简写也是前端开发工程师的基本功之一.今天我们系统地总结一下CSS属性的缩写. 色彩缩写 色彩的缩写最简单 ...