問題描述
當 TransactionScope 首次出現時,我遇到了一些嚴重的問題,以使其在我的開發機器 (XP) 和我們的數據庫服務器 (Windows Server 2003) 之間工作.
When TransactionScope first came out, I ran into some serious issues getting it to work between my dev machine (XP) and our database server (Windows Server 2003).
當我深入研究它時,這似乎是一個棘手且普遍的問題,有可能成為生產中的一個頭疼問題,所以我決定不以這種方式處理事務(盡管我非常喜歡這種語法并且我真的很想讓它工作).
When I looked into it more, this appeared to be a tricky and widespread issue that had a chance of becoming a headache in production, so I decided not to handle transactions this way (even though I like the syntax a lot and I really wanted it to work).
這些問題是否仍然存在,或者使用起來是否安全?你現在經常使用它沒有問題嗎?
Are these problems still out there or is this safe to use? Do you use this regularly now without issues?
非常感謝!
注意:已經很久了,但我認為這個問題與 Distribute Transaction Coordinator 有關.我擺弄了很長時間,但始終無法讓它發揮作用.
Note: It has been a long time now, but I think the issue had something to do with Distribute Transaction Coordinator. I fiddled with it for a long time and was never able to get it working.
推薦答案
Rick Strahl 有一篇關于事務范圍和 LINQ to SQL 的精彩博文 此處.它的上下文更像是 LINQ to SQL,但我認為有一些適用的原則可以幫助您解決問題.
Rick Strahl has a great post about transaction scope and LINQ to SQL here. Its context is more LINQ to SQL, but I think that there are some principles that apply which could help you solve your question.
為了更具體地回答您的問題,以下是 Strahl 對 TransactionScope 的看法:
to more specifically answer your question, here's what Strahl has to say about TransactionScope:
傳統上 TransactionScope 是一個圍繞分布式事務協調器 (DTC) 的 .NET 包裝器,但它的功能有所擴展.一個問題是 DTC 在資源使用方面相當昂貴,并且它要求 DTC 服務實際運行在機器上(另一個服務在客戶端安裝時特別麻煩).
Traditionally TransactionScope was a .NET wrapper around the Distributed Transaction Coordinator (DTC) but it’s functionality has expanded somewhat. One concern is that the DTC is rather expensive in terms of resource usage and it requires that the DTC service is actually running on the machine (yet another service which is especially bothersome on a client installation).
但是,最近對 TransactionScope 和 SQL Server 客戶端驅動程序的更新使得可以使用 TransactionScope 類及其提供的易用性,而無需 DTC,只要您針對單個數據庫運行并使用單個一致的連接字符串
However, recent updates to TransactionScope and the SQL Server Client drivers make it possible to use TransactionScope class and the ease of use it provides without requiring DTC as long as you are running against a single database and with a single consistent connection string
這篇關于TransactionScope:它變得更好了嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!