SqlTransaction after catch transaction connection is null

前端 未结 2 1693
花落未央
花落未央 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.

提交回复
热议问题