久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

為什么 TransactionScope 不適用于實體框架?

Why doesn#39;t TransactionScope work with Entity Framework?(為什么 TransactionScope 不適用于實體框架?)
本文介紹了為什么 TransactionScope 不適用于實體框架?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

請看下面的代碼.如果我初始化多個實體上下文,那么我會在 僅第二組代碼 上得到以下異常.如果我注釋掉第二組就可以了.

See the code below. If I initialize more than one entity context, then I get the following exception on the 2nd set of code only. If I comment out the second set it works.

{"底層提供程序在打開時失敗."}

{"The underlying provider failed on Open."}

內部:{與底層事務管理器的通信失敗."}

Inner: {"Communication with the underlying transaction manager has failed."}

內部:{錯誤 HRESULT E_FAIL 已從對 COM 組件的調用返回."}

Inner: {"Error HRESULT E_FAIL has been returned from a call to a COM component."}

請注意,這是一個示例應用程序,我知道連續創建 2 個上下文沒有意義.但是,生產代碼確實有理由在同一個 TransactionScope 中創建多個上下文,并且這是無法更改的.

Note that this is a sample app and I know it doesn't make sense to create 2 contexts in a row. However, the production code does have reason to create multiple contexts in the same TransactionScope, and this cannot be changed.

編輯

這是我之前嘗試設置 MS-DTC 的一個問題.它似乎在服務器和客戶端上都啟用了.我不確定它是否設置正確.另請注意,我嘗試這樣做的原因之一是 TransactionScope 中的現有代碼使用 ADO.NET 和 Linq 2 Sql...我希望它們也使用相同的事務.(這聽起來可能很瘋狂,但如果可能的話,我需要讓它發揮作用).

Here is a previous question of me trying to set up MS-DTC. It seems to be enabled on both the server and the client. I'm not sure if it is set up correctly. Also note that one of the reasons I am trying to do this, is that existing code within the TransactionScope uses ADO.NET and Linq 2 Sql... I would like those to use the same transaction also. (That probably sounds crazy, but I need to make it work if possible).

如何在 C# 中使用 TransactionScope?

解決方案

Windows 防火墻阻止了與 MS-DTC 的連接.

using(TransactionScope ts = new System.Transactions.TransactionScope())
        {
                using (DatabaseEntityModel o = new DatabaseEntityModel())
                {
                    var v = (from s in o.Advertiser select s).First();
                    v.AcceptableLength = 1;
                    o.SaveChanges();
                }

                //-> By commenting out this section, it works
                using (DatabaseEntityModel o = new DatabaseEntityModel())
                {
                    //Exception on this next line
                    var v = (from s1 in o.Advertiser select s1).First();                         v.AcceptableLength = 1;
                    o.SaveChanges();
                }
                //->

                ts.Complete();
        }

推薦答案

由于某種原因,您的 MS-DTC(分布式事務協調器)無法正常工作.MS-DTC用于協調跨多個異構資源的事務結果,包括多個sql連接.

Your MS-DTC (Distributed transaction co-ordinator) is not working properly for some reason. MS-DTC is used to co-ordinate the results of transactions across multiple heterogeneous resources, including multiple sql connections.

看看此鏈接了解有關正在發生的事情的更多信息.

Take a look at this link for more info on what is happening.

基本上,如果您確保 MS-DTC 正在運行并且正常工作,那么使用 2 個 ADO.NET 連接應該沒有問題 - 無論它們是實體框架連接還是任何其他類型.

Basically if you make sure your MS-DTC is running and working properly you should have no problems with using 2 ADO.NET connections - whether they are entity framework connections or any other type.

這篇關于為什么 TransactionScope 不適用于實體框架?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

LINQ to SQL and Concurrency Issues(LINQ to SQL 和并發問題)
SQL Server 2005 Transaction Level and Stored Procedures(SQL Server 2005 事務級和存儲過程)
Yield return from a try/catch block(try/catch 塊的收益回報)
Should I call Parameters.Clear when reusing a SqlCommand with a transation?(重用帶有事務的 SqlCommand 時,我應該調用 Parameters.Clear 嗎?)
Does SqlTransaction need to have Dispose called?(SqlTransaction 是否需要調用 Dispose?)
Reason for System.Transactions.TransactionInDoubtException(System.Transactions.TransactionInDoubtException 的原因)
主站蜘蛛池模板: 亚洲一区中文字幕 | 日本a∨精品中文字幕在线 亚洲91视频 | 国产精品久久久久久久久久 | 中文字幕在线中文 | 日韩在线高清 | 一区二区三区四区av | 久久亚洲国产精品 | 久久国产欧美日韩精品 | 日韩在线免费视频 | 成人黄色a | 亚洲免费精品一区 | 一区二区三区久久久 | www.日本国产 | 国产98色在线 | 日韩 | 中文在线www| 91免费观看国产 | 91国内视频在线 | 99精品久久99久久久久 | 国产精华一区 | 无吗视频| 自拍偷拍精品 | 欧洲成人 | 久久久久久国产精品久久 | 超碰地址 | 久久亚洲欧美日韩精品专区 | 日本精品视频在线 | 91久久国产综合久久 | 欧美国产精品一区二区三区 | 在线亚洲一区二区 | 欧美中文字幕一区二区三区亚洲 | 久久高清国产视频 | 天天想天天干 | 国产精品久久久久久久久久久久久 | 亚洲一区视频在线 | 成人h视频在线 | 精品一区二区三区中文字幕 | 国产一区二区在线免费观看 | 91精品国产色综合久久 | 亚洲视频区 | 91精品欧美久久久久久久 | 欧美日韩高清在线观看 |