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

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

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

問題描述

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

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."}

內(nèi)部:{與底層事務(wù)管理器的通信失敗."}

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

內(nèi)部:{錯誤 HRESULT E_FAIL 已從對 COM 組件的調(diào)用返回."}

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

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

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.

編輯

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

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(分布式事務(wù)協(xié)調(diào)器)無法正常工作.MS-DTC用于協(xié)調(diào)跨多個異構(gòu)資源的事務(wù)結(jié)果,包括多個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.

看看此鏈接了解有關(guān)正在發(fā)生的事情的更多信息.

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

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

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.

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

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

相關(guān)文檔推薦

LINQ to SQL and Concurrency Issues(LINQ to SQL 和并發(fā)問題)
SQL Server 2005 Transaction Level and Stored Procedures(SQL Server 2005 事務(wù)級和存儲過程)
Yield return from a try/catch block(try/catch 塊的收益回報)
Should I call Parameters.Clear when reusing a SqlCommand with a transation?(重用帶有事務(wù)的 SqlCommand 時,我應(yīng)該調(diào)用 Parameters.Clear 嗎?)
Does SqlTransaction need to have Dispose called?(SqlTransaction 是否需要調(diào)用 Dispose?)
Reason for System.Transactions.TransactionInDoubtException(System.Transactions.TransactionInDoubtException 的原因)
主站蜘蛛池模板: 91午夜精品亚洲一区二区三区 | 91av免费 | 国产91av在线 | 国产黄色大片 | 精品一区二区免费视频 | 青青在线视频 | 欧美顶级黄色大片免费 | 中国一级黄色 | 青青草久久 | 天天摸天天爽 | 午夜视频在线看 | 看片黄全部免费 | 日韩在线观看中文字幕 | a级片网址 | 黄色一级录像 | 欧美成人精品欧美一级乱黄 | 爱爱免费小视频 | 日韩黄色录像 | 欧美福利视频 | 麻豆精品国产 | av免费观看在线 | 日韩av在线免费播放 | 欧美一级在线播放 | 国产精品一区一区三区 | 中国av在线播放 | 国产一区二区在线播放 | 五月婷婷激情网 | 免费91网站| 欧美日韩精品久久久免费观看 | 日日摸天天添天天添破 | 狠狠干夜夜 | 国产精品视频免费看 | 青青国产视频 | 国产精品一二 | 伊人色综合网 | 黄a视频| 看片黄全部免费 | 久久性色 | 欧美成人小视频 | 91欧美在线 | 男人天堂av网 |