VB.NET - Implicit and Explicit Transactions

别等时光非礼了梦想. 提交于 2020-03-20 14:54:00

问题


What are the benefits of using implicit transactions (TransactionScope) over explicit transactions (SQLTransaction)?

I have spent some time investigating this and there are lots of websites that explain the differences between the two, which I do understand e.g. this one: http://sqlserverpedia.com/wiki/Transaction_Overview, and this one: named explicit & implicit transactions. I understand the properties of a Transaction i.e. ACID. I have also looked at the documentation on MSDN.

I believe that implicit transactions are more flexible and easier to use (because rollback is done for you and the transaction is not tied to a specific connection). I believe that explicit transactions give you more control e.g. when to rollback. I wanted to confirm: a) whether or not what I have said is true, b) Is there any criteria used to decide whether to use an implicit or explicit transaction.

On MSDN it says: "It is highly recommended that you use the easier implicit model for development"


回答1:


Explicit transactions are a thing of the past. Don't use them unless you have a really good reason, and I can't think of any. TransactionScope is the way to go, practically always.

Don't worry about DTC, TransactionScope is smart enough to use the DTC only when two resources need to be coordinated. If you're accessing just one database, TransactionScope will be every bit as fast as explicit transactions.




回答2:


I suggest avoiding using MSDTC if at all possible, unless you have the chops troubleshoot, write exhaustive troubleshooting guides on it, and write thorough explanation to users of your software about how to configure it. For example, users will need to know how to set up its authentication, how to ensure the DTC service is running make sure remote machines can communicate, how to configure SQL with FQDN for cross domain transactions, etc. It's been nothing but a problem for me, for years. Slowly have been winning the war to get it removed from the system. In other words, yes. Go ahead and use if it you want to guarantee issues with it for the next ten years. IMHO, it is not an enterprise class tool. There is nothing automagical about it at all.



来源:https://stackoverflow.com/questions/14253048/vb-net-implicit-and-explicit-transactions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!