One or more errors occurred. (BeginExecuteReader requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized.

查询数据库时,net 5抛出异常如下:

One or more errors occurred. (BeginExecuteReader requires the command to have a transaction when the connection assigned to the command is in a pending local transaction.  The Transaction property of the command has not been initialized.


错误代码:

图片.png

最佳解决方案

原因分析

发生这个异常的原因就是在事务里面另外打开了数据库连接导致了冲突

1、可以把查询放到事务外面完成

2、也可以直接原来的事务链接进行查询,比如 车辆信息哪里的代码
图片.png


程序员生活志 T0 被采纳率100%
2021-08-05 12:56
打赏 0 1
页面统计
758 访问
0 帮助
0.00 打赏

hierror 2019 © hierror.com 京ICP备13026190号-1

通知消息
  • 暂无任何消息