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

如何在 C# 中使用 TransactionScope?

How to use TransactionScope in C#?(如何在 C# 中使用 TransactionScope?)
本文介紹了如何在 C# 中使用 TransactionScope?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試使用 TransactionScope,但不斷收到以下異常.
如果重要的話,該應用程序運行在與數據庫不同的機器上.我使用的是 SQL Server 2005.

<塊引用>

分布式事務管理器 (MSDTC) 的網絡訪問已被禁用.請在安全配置中為網絡訪問啟用 DTCMSDTC 使用組件服務管理工具.

using (TransactionScope tsTransScope = new TransactionScope()){//在這里做事tsTransScope.Complete();}

編輯

我根據反饋做了一些更改.現在我收到此錯誤:

<塊引用>

調用 COM 組件時返回了錯誤 HRESULT E_FAIL."
與底層事務管理器的通信失敗."

解決方案我認為接受的答案解決了我遇到的最初問題.第二個錯誤似乎特定于實體框架.我會為此發布另一個問題.

以下是客戶端的屬性:
有這個有趣的建議:

<塊引用>

另一個配置設置需要注意(雖然我認為這是一個不常見的情況)是RestrictRemoteClients 注冊表項.如果此鍵的值設置為 2(RPC_RESTRICT_REMOTE_CLIENT_HIGH) 然后MSDTC 網絡交易不會被能夠正常工作.MSDTC 支持只有 RPC_RESTRICT_REMOTE_CLIENT_NONE(0) 和RPC_RESTRICT_REMOTE_CLIENT_DEFAULT (1)值.看http://www.microsoft.com/technet/prodtechnol/winxppro/maintain/sp2netwk.mspx#XSLTsection128121120120有關更多信息限制遠程客戶端.

最后,雖然不是特定于您的問題,但使用 TransactionScope 類時需要注意的一個非常重要的事情是它的默認設置是使用 可序列化的事務隔離級別.Serializable 是限制性最強的隔離級別,坦率地說,它被選為默認級別令人驚訝.如果您不需要這種級別的鎖定,我強烈建議在實例化 TransactionScope 時將隔離級別設置為限制較少的選項 (ReadCommitted):

var scopeOptions = new TransactionOptions();scopeOptions.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;scopeOptions.Timeout = TimeSpan.MaxValue;使用 (var scope = new TransactionScope(TransactionScopeOption.Required,范圍選項)){//你的代碼在這里}

I am trying to use TransactionScope, but keep getting the exception below.
The app is running on a different machine than the database, if that matters. I am using SQL Server 2005.

Network access for Distributed Transaction Manager (MSDTC) has been disabled. Please enable DTC for network access in the security configuration for MSDTC using the Component Services Administrative tool.

using (TransactionScope tsTransScope = new TransactionScope())
{
    //Do stuff here
    tsTransScope.Complete();
}

Edit

I made some changes based on the feedback. Now I'm getting this error:

"Error HRESULT E_FAIL has been returned from a call to a COM component."
"Communication with the underlying transaction manager has failed."

Solution I think the accepted answer fixed the initial issue I was getting. The 2nd error seems to be specific to Entity Framework. I'll post another question for it.

Here are the properties on the client:
Client http://www.portnine.com/data/images/Misc/client.jpg

Here are the properties on the server:
Server http://www.portnine.com/data/images/Misc/server.jpg

解決方案

You need to enable network DTC access as described in this Microsoft TechNet Article. This change may have to be made on both the database and application servers. Often times DTC is already turned on a database server so I'd look at the application server first.

Here is a screen shot of what we use except for the "Allow Remote Administration" option:

I have not run into the HRESULT E_Fail issue you are now having but this article on XP SP2 and transactions had this interesting suggestion:

Another configuration setting that you need to be aware (although I consider it to be an uncommon scenario) is RestrictRemoteClients registry key. If the value of this key is set to 2 (RPC_RESTRICT_REMOTE_CLIENT_HIGH) then MSDTC network transactions will not be able to work properly. MSDTC supports only RPC_RESTRICT_REMOTE_CLIENT_NONE (0) and RPC_RESTRICT_REMOTE_CLIENT_DEFAULT (1) values. See http://www.microsoft.com/technet/prodtechnol/winxppro/maintain/sp2netwk.mspx#XSLTsection128121120120 for more info on RestrictRemoteClients.

Finally, while not specific to your issue a very important thing to note about using the TransactionScope class is that its default setting is to utilize a Transaction Isolation Level of Serializable. Serializable is the most restrictive of the isolation levels and frankly its surprising that it was chosen as the default. If you do not need this level of locking I would highly recommend setting the isolation level to a less restrictive option (ReadCommitted) when instantiating a TransactionScope:

var scopeOptions = new TransactionOptions();
scopeOptions.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
scopeOptions.Timeout = TimeSpan.MaxValue;

using (var scope = new TransactionScope(TransactionScopeOption.Required,
    scopeOptions))
{
    // your code here
}

這篇關于如何在 C# 中使用 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 的原因)
主站蜘蛛池模板: 国产91在线精品 | 欧美一级全黄 | 国产成人综合一区二区三区 | 久久久久1 | 视频第一区 | 国产精品国产a | 精品国产欧美一区二区三区成人 | 久久国产精品一区二区三区 | 免费看淫片 | 青青草一区二区三区 | 亚洲美女一区 | 精品欧美一区二区久久久伦 | 国产成人99久久亚洲综合精品 | 丁香婷婷在线视频 | 国产成人亚洲精品 | 成人免费淫片aa视频免费 | 欧美日韩高清在线一区 | 亚洲欧美一区二区三区在线 | 91久久精品一区二区二区 | 在线观看国产视频 | 91久久伊人 | 久久亚洲国产精品日日av夜夜 | 成在线人视频免费视频 | 欧美一级淫片007 | 二区av | 成人h视频在线 | 欧美日韩在线一区二区三区 | 亚洲一区二区网站 | 黑人中文字幕一区二区三区 | 成人免费视频观看 | 国产亚洲一区二区精品 | av官网在线 | 日韩精品一区二区三区视频播放 | 日韩在线观看中文字幕 | 久久精品亚洲欧美日韩精品中文字幕 | 国产精品69久久久久水密桃 | 亚洲手机视频在线 | 国产成人精品999在线观看 | 欧美一级特黄aaa大片在线观看 | 欧美啪啪 | 国产黄色大片网站 |