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 ...
随机推荐
- JavaScript -- Enumerator
-----022-Enumerator.html----- <!DOCTYPE html> <html> <head> <meta http-equiv=&q ...
- INSERT INTO IF EXISTS
INSERT INTO books (name) SELECT 'MySQL Manual' FROM dual WHERE NOT EXISTS (SELECT id FROM booksWHERE ...
- Linux配置多个Tomcat同时运行
Linux系统下怎样配置多个Tomcat同时运行呢,首先修改变量为第一个tomcat,然后修改第二个tomcat启动的脚本 1.修改环境变量 # vi /etc/profile ####### 工程1 ...
- Ansible工作流程详解
1:Ansible的使用者 ------>Ansible的使用者来源于多种维度,(1):CMDB(Configuration Management Database,配置管理数据库),CMDB存 ...
- SOA和微服务架构的区别?
转自知乎:https://www.zhihu.com/question/37808426/answer/93335393 SOA和微服务架构的区别? 微服务架构强调的第一个重点就是业务系统需要彻底的组 ...
- Spring注解 @Configuration
Spring注解 @Configuration 一.@Configuration的作用 二.@Configuration的Spring容器启动方式 三.不加@Configuration的@Bean的解 ...
- Unix/Linux系统管理技术手册学习笔记——shell
创建日期:2016/02/29 更新日期:2016/02/29 shell变量赋值时不能在等号两边留空白,否则shell会把变量名误认为是命令名 双引号括起来的变量可以进行替换(用*和?这样的文件名匹 ...
- ApiGen 4.0配置项
Usage: generate [-s|--source="..."] [-d|--destination="..."] [--access-levels=&q ...
- Netty 核心组件 Pipeline 源码分析(二)一个请求的 pipeline 之旅
目录大纲: 前言 针对 Netty 例子源码做了哪些修改? 看 pipeline 是如何将数据送到自定义 handler 的 看 pipeline 是如何将数据从自定义 handler 送出的 总结 ...
- ASP.NET Core (二):入门
上一篇:ASP.NET Core(一):简介 下一篇:(待续) 英文原版:Getting Started 1. 安装 .NET Core 2. 创建 .NET Core 项目 在命令提示符窗口输入命令 ...