SqlTransaction after catch transaction connection is null

隐身守侯 提交于 2019-12-01 19:03:35

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!