今天写写通用日志的时候,最后自己测试的时候,发现同一个数据上下文中,如果开启了事务, 手写sql要对某个表进行查询的话,会造成报错,在网上找了几种解决办法,觉得改sql是最简单, 在要查询的表的表名后,添加“with(nolock)”,就这样就可以避免事务查询表时,对表添加锁。 写全面就是:select * from 表名 with(nolock) where 还有一种就是更改command上的transaction属性,这种没有尝试没用过 还不清楚
{collapse-item label="报错内容" open}
ExecuteReader 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.”
{/collapse-item}
本文共 143 个字数,平均阅读时长 ≈ 1分钟
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有