Why use a using statement with a SqlTransaction?

前端 未结 9 1394
佛祖请我去吃肉
佛祖请我去吃肉 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:30

    In the end, using is just a shortcut for a pattern. But it's a very useful and helpful shortcut, because it makes sure you implement the pattern correctly and means you can do it with less code.

    In this case, you haven't implemented the pattern correctly. What happens in your code if the call to tr.RollBack() also throws an exception?

提交回复
热议问题