惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Project Zero
Project Zero
月光博客
月光博客
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
O
OpenAI News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Know Your Adversary
Know Your Adversary
Last Week in AI
Last Week in AI
S
Securelist
Engineering at Meta
Engineering at Meta
博客园 - 司徒正美
P
Privacy & Cybersecurity Law Blog
T
Tailwind CSS Blog
F
Fortinet All Blogs
博客园 - 三生石上(FineUI控件)
Scott Helme
Scott Helme
MyScale Blog
MyScale Blog
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
C
Cisco Blogs
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
小众软件
小众软件
U
Unit 42
Microsoft Azure Blog
Microsoft Azure Blog
Hacker News: Ask HN
Hacker News: Ask HN
Hugging Face - Blog
Hugging Face - Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
SecWiki News
SecWiki News
宝玉的分享
宝玉的分享
P
Proofpoint News Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Hackread – Cybersecurity News, Data Breaches, AI and More
L
Lohrmann on Cybersecurity
IT之家
IT之家
Security Archives - TechRepublic
Security Archives - TechRepublic
I
InfoQ
S
Security @ Cisco Blogs
Webroot Blog
Webroot Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
F
Full Disclosure
D
Darknet – Hacking Tools, Hacker News & Cyber Security
The GitHub Blog
The GitHub Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Jina AI
Jina AI
Cyberwarzone
Cyberwarzone
人人都是产品经理
人人都是产品经理
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
B
Blog RSS Feed
Apple Machine Learning Research
Apple Machine Learning Research

博客园 - andy.wu

聊聊除了生产率之外的东西,比如赚钱效率 一次思维锻炼,使用拼音模糊匹配中文 - andy.wu - 博客园 一些需要解决的问题(Win32) svn howto: svn合并时报错:retrieval of mergeinfo unsupported by 。 Windows Mobile应用开发(1):使用Win32 SDK 开发屏幕手电程序 vs(2005 and 2008)中使用vc++创建智能设备项目失败的正确解决方案 思考:google的opensocial的实现原理 思考:日期类型的数据应该用什么样的具体形式存储到数据库? google got crazy!!! EnableViewState详细分析 - andy.wu - 博客园 NHibernate Tips: 要注意模型与数据库在Null方面的匹配 AjaxPro基础知识 and FAQ 在iis 6中使用共享目录作为虚拟目录 初学wpf感想 Sql Server 2005全文检索中碰到的问题和分析 asp.net faq: 在html文件中,用js获取session? 给博客园首页管理的建议 china-pub,当当,卓越购书经验谈 使用Emacs代替Windows下的Command shell
经验:使用.net 2.0中的TransactionScope碰到的问题
andy.wu · 2008-04-14 · via 博客园 - andy.wu

经验:使用.net 2.0中的TransactionScope碰到的问题

概述:不能在同一个TransactionScope中打开多个连接对象

TransactionScope真的是很方便的,具体的使用也很简单,MSDN上有详细描述。不过我在使用过程中发现了一个问题,那就是无法在同一个TransactionScope中打开多个连接对象。示例代码如下,示例中是连接到同一实例的同一数据库,但连接到不同实例的不同数据库也是同样的结果。

具体原因还需具体分析,我碰到的情况不一定代表就是正确的情况,还请大家批评。

[Test]

public void TestTransactionScope()

{

    using (TransactionScope ts = new TransactionScope())

    {

        string cnstr = @"Data Source=cs1\sqlexpress;Database=fugao_dev;User ID=sa;Password=123;";

        SqlConnection cn1 = new SqlConnection(cnstr);

        cn1.Open();

        using (TransactionScope ts2 = new TransactionScope())

        {

            SqlConnection cn2 = new SqlConnection(cnstr);

            cn2.Open();

        }

    }

}

[Test]

public void TestTransactionScopeA()

{

    using (TransactionScope ts = new TransactionScope())

    {

        string cnstr = @"Data Source=cs1\sqlexpress;Database=fugao_dev;User ID=sa;Password=123;";

        SqlConnection cn1 = new SqlConnection(cnstr);

        cn1.Open();

        SqlConnection cn2 = new SqlConnection(cnstr);

        cn2.Open();

    }

}

以上测试都抛出了异常,并且运行时间很长,象死机一下

System.Transactions.TransactionManagerCommunicationException : 与基础事务管理器的通信失败。

  ----> System.Runtime.InteropServices.COMException : 对 COM 组件的调用返回了错误 HRESULT E_FAIL。