SqlTransaction after catch transaction connection is null

前端 未结 2 1669
花落未央
花落未央 2021-01-18 09:56

I have a loop where I call stored procedure with different parameter value. Next call cmd.ExecuteNonQuery(); I use transaction to save all or rollback, and chec

相关标签:
2条回答
  • 2021-01-18 10:32

    Ran into a similar issue. In my case it was happening for a specific SqlException. Most exceptions would be caught and handled just fine, but whenever I got a conversion error (such as trying to convert a string to a number) it would automatically end the transaction.

    To fix this, I had to implement data checking (good idea anyway) prior to building/submitting the command object. Hope this helps others seeing this weird error.

    0 讨论(0)
  • 2021-01-18 10:33

    I also met this odd problem (converting nvarchar to integer exception).

    In my solution, I rebuild the transacton if found the underlying connection is null. But it's a dirty work.

    enter image description here

    0 讨论(0)
提交回复
热议问题