Why use a using statement with a SqlTransaction?

前端 未结 9 1365
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-02 11:27

I\'ve been running into some problems concerning a SqlTransaction I\'m using in my code. During my Googling I see many people using a using statement with a SqlTransaction.<

9条回答
  •  时光取名叫无心
    2020-12-02 11:40

    The reason for this is that the SqlTransaction object will roll back in its Dispose() method if it was not explicitly committed (e.g. if an exception is thrown). In other words, it has the same effect as your code, just a little bit cleaner.

提交回复
热议问题