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 ...
随机推荐
- docker namespaces
https://docs.docker.com/engine/security/userns-remap/#prerequisites 注:以下验证环境为centos7.5 docker 18.09. ...
- find_package()的查找*.cmake的顺序
1. find_package(<Name>)命令首先会在模块路径中寻找 Find<name>.cmake,这是查找库的一个典型方式.具体查找路径依次为CMake: 变量${C ...
- kafka主题管理
若代理设置了 auto.create.topics.enable=true,这样还未创建topic就往kafka发送消息时, 会自动创建一个 ${num.partitions}个分区和{default ...
- 使用Gitlab一键安装包后的日常备份恢复与迁移
Gitlab 创建备份 使用Gitlab一键安装包安装Gitlab非常简单, 同样的备份恢复与迁移也非常简单. 使用一条命令即可创建完整的Gitlab备份: gitlab-rake gitlab:ba ...
- Spark2.1.0——内置RPC框架详解
Spark2.1.0——内置RPC框架详解 在Spark中很多地方都涉及网络通信,比如Spark各个组件间的消息互通.用户文件与Jar包的上传.节点间的Shuffle过程.Block数据的复制与备份等 ...
- zoj 2724 Windows Message Queue(使用priority_queue容器模拟消息队列)
题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2724 题目描述: Message queue is the b ...
- C# Owin初探 概念理解(一)
本文是阅读网上大牛的文章总结而成. 目录 1.Owin定义 2.为什么要用Owin 3.作用 4.总结 1.Owin定义 Owin是Open Web Interface For .NET.也就是.Ne ...
- .Net下SQLite的DBHelp
怎样获取SqLite请参考初识SqlLite ---.net连接数据库,怎样在SQLite使用Linq请参考在C#中利用Nuget包使用SQLite数据库和Linq to SQLite using S ...
- Linux下的压缩文件剖析 (tar/gzip的区别)
Linux下的压缩文件剖析 对于刚刚接触Linux的人来说,一定会给Linux下一大堆各式各样的文件名给搞晕.别个不说,单单就压缩文件为例,我们知道在Windows下最常见的压缩文件就只有两种,一是, ...
- EWS 流通知订阅邮件
摘要 查找一些关于流通知订阅邮件的资料,这里整理一下. 核心代码块 using System; using System.Collections.Generic; using System.Linq; ...