Cannot access SqlTransaction object to rollback in catch block

前端 未结 7 1089
我寻月下人不归
我寻月下人不归 2020-12-02 15:43

I\'ve got a problem, and all articles or examples I found seem to not care about it.

I want to do some database actions in a transaction. What I want to do is very s

7条回答
  •  误落风尘
    2020-12-02 16:15

    Microsoft samples, place the begin trans outside of the try/catch see this msdn link. I assume that the BeginTransaction method should either throw an exception OR begin a transaction but never both (although the documentation does not say this is impossible).

    However, you may be better of using TransactionScope which manages a lot of the (not so) heavy lifting for you: this link

提交回复
热议问题