If TransactionScope will close database connections
问
Do TransactionScope work with closed database connections?
using (var transaction = new TransactionScope(TransactionScopeOption.Required))
{
// creates a new connection, does stuff, commit trans and close
repos1.DoSomething(); // creates a new connection, does stuff, commit trans and close
repos2.DoSomething(); transaction.Complete();
}
答
Yes, that should work fine. Internally, the connections should be kept open until the transaction completes. Keep in mind that DTC may be required if multiple connections are used though, even if they are to the same database.
意思就是说在TransactionScope范围中的repos1.DoSomething中创建的DbConnection,并不会在repos1.DoSomething中因为调用了DbConnection.Close而真正关闭,ADO.NET会在repos2.DoSomething里创建并开启另一个DbConnection时,重用repos1.DoSomething创建的DbConnection,在整个TransactionScope范围结束(即using代码块结束)后,ADO.NET才会从底层真正关闭repos1.DoSomething中的DbConnection,这一切都是由ADO.NET 内部管理的。
using (var transaction = new TransactionScope(TransactionScopeOption.Required))
{
// creates a new connection, does stuff, commit trans and close
repos1.DoSomething(); // creates a new connection, does stuff, commit trans and close
repos2.DoSomething(); transaction.Complete();
}
If TransactionScope will close database connections的更多相关文章
- ERROR 000732:Output Geodatabase:Dataset Database Connections\Connection to localhost.sde\SDE.Dataset does not exist or is not supported
ArcCatalog 10中向SDE 数据集导入要素类时,出错:ERROR 000732:Output Geodatabase:Dataset Database Connections\Connect ...
- eclipse中创建DataBase Connections
1.window --> show view --> other --> Data Management --> Data Exploerer --> ok: 2.右键单 ...
- handle exceptions, opening and closing database connections
https://www.tutorialspoint.com/spring/spring_jdbc_framework.htm Spring - JDBC Framework Overview Whi ...
- 回滚原理 Since database connections are thread-local, this is thread-safe.
mysql django 实践: django @transaction.atomic 机制分析 1.数据库清空表Tab 2.请求django-view @transaction.at ...
- 解决:eclipse配置Database Connections报错Communications link failure Last packet sent to the server was 0 ms ago
网上各式各样的问题,不过我的问题在于我开了Proxifier,导致链接localhost的时候被拦截...把Proxifier关了就好了 以后遇到这种问题.连不上数据库啊,连不上本地的服务器啊,先检查 ...
- P6 Professional Installation and Configuration Guide (Microsoft SQL Server Database) 16 R1
P6 Professional Installation and Configuration Guide (Microsoft SQL Server Database) 16 R1 May ...
- Database API
Database API Introduction Basic Usage Selects Joins Aggregates Raw Expressions Inserts Updates Delet ...
- How to Kill All Processes That Have Open Connection in a SQL Server Database[关闭数据库链接 最佳方法] -摘自网络
SQL Server database administrators may frequently need in especially development and test environmen ...
- [Windows Azure] Managing SQL Database using SQL Server Management Studio
Managing Windows Azure SQL Database using SQL Server Management Studio You can use Windows Azure SQL ...
随机推荐
- selenium3 无人工干预地自动下载某个文件
一:主要内容 下载效果展示 代码内容展示 saveToDisk不生效说明,即文件没有下载下来解决办法 二:展示效果 1.下载效果展示 用selenium3无人工干预的自动下载该文件到指定路径下,如:D ...
- 软件架构设计学习总结(18):MVC三层架构在各框架(jsp+servlet + Struts1+ Struts2+ springMVC)中的特征
1.基于web开发中最原始的jsp+Servlet 图形化理解jsp+servlet结构: 1.从结构上分析jsp+servlet图解原理: 在基于mvc设计模式下的最原始的jsp+Servlet ...
- 第一章 Java Web工作原理
一:在本章我们将学到如下的内容 >HTTP协议原理 >服务器端Web编程原理 >Servlet与Web容器 >Java Web应用程序的组成 >Tomcat介绍 一:1. ...
- getInitParameter方法
在ServletConfig和ServletContext都有getInitParameter方法, 这两个方法的都能从web.xml中获取参数,但是是有区别的. 1. web.xml文件 <? ...
- layer插件学习——提示层
本文是自己整理的关于layer插件的提示层的结果 一.准备工作 下载jQuery插件和layer插件,并引入插件(注意:jQuery插件必须在layer插件之前引用) 百度云资源链接: jQuery插 ...
- (转)注解用法详解—@@SuppressWarnings
一.前言 编码时我们总会发现如下变量未被使用的警告提示: 上述代码编译通过且可以运行,但每行前面的“感叹号”就严重阻碍了我们判断该行是否设置的断点了.这时我们可以在方法前添加 @SuppressWar ...
- .1-浅析express源码之入口文件
鸽了鸽了,webpack源码大垃圾,看了那么久,感觉自己越来越渣……还是换个口味,node了解一下? 尝试从express框架源码入手,学习一下node的http模块相关的知识. 入口文件 先从框架的 ...
- 使用 Swagger UI 与 Swashbuckle 创建 RESTful Web API 帮助文件(转)
作者:Sreekanth Mothukuru2016年2月18日 本文旨在介绍如何使用常用的 Swagger 和 Swashbuckle 框架创建描述 Restful API 的交互界面,并为 API ...
- 【游记】Noip2018
Day -1 Noip还有1天,加油!!! 今天上午就肝一肝树形DP,维护一些玄学差分,和前缀数组什么的吧 下午以及晚上搞一搞记忆化搜索和最朴素的DFS这样子吧. 还要打一打板子也是极有必要的qwq ...
- Java集合类源码解析:LinkedHashMap
前言 今天继续学习关于Map家族的另一个类 LinkedHashMap .先说明一下,LinkedHashMap 是继承于 HashMap 的,所以本文只针对 LinkedHashMap 的特性学习, ...