解决ExecuteReader requires the command to have a transaction when the connection assigned to the command is in a pending local transaction.
2008-05-15 09:31
796 查看
ExecuteReader requires the command to have a transaction when the connection assigned to the command is in a pending local transaction.
同一个connection,在update的command上启动了一个transaction,后面一个查询的command,没有设置transaction属性,所以出了这个exception.
解决方法:
将update的command加到select的command上去.
SqlConnection conn = new SqlConnection("");
SqlCommand updateCmd = new SqlCommand("update", conn);
updateCmd.Transaction = conn.BeginTransaction();
int rows = updateCmd.ExecuteNonQuery();
SqlCommand selectCmd = new SqlCommand("select ", conn);
selectCmd.Transaction = updateCmd.Transaction;//important
SqlDataReader reader = selectCmd.ExecuteReader();
//.
同一个connection,在update的command上启动了一个transaction,后面一个查询的command,没有设置transaction属性,所以出了这个exception.
解决方法:
将update的command加到select的command上去.
SqlConnection conn = new SqlConnection("");
SqlCommand updateCmd = new SqlCommand("update", conn);
updateCmd.Transaction = conn.BeginTransaction();
int rows = updateCmd.ExecuteNonQuery();
SqlCommand selectCmd = new SqlCommand("select ", conn);
selectCmd.Transaction = updateCmd.Transaction;//important
SqlDataReader reader = selectCmd.ExecuteReader();
//.
相关文章推荐
- ExecuteScalar requires the command to have a transaction when the connection assigned to the command is in a pending
- The goal you specified requires a project to execute but there is no POM in this directory...
- The goal you specified requires a project to execute but there is no POM in this directory 错误
- The goal you specified requires a project to execute but there is no POM in this directory
- vs2005下出现“Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive”的解决方法
- maven报错 the goal you specified requires a project to execute but there is no POM in this direct...
- [ERROR] The goal you specified requires a project to execute but there is no POM in this directory
- The goal you specified requires a project to execute but there is no POM in 错误
- The final local variable cannot be assigned, since it is defined in an enclosing type的解决办法(把变量从局部编程)
- The goal you specified requires a project to execute but there is no POM in this directory
- The connection to adb is down, and a severe error has occured解决
- android中The connection to adb is down,问题和解决
- android中The connection to adb is down,问题和解决
- 安卓模拟器不能启动:The connection to adb is down, and a severe error has occurred解决方法
- android解决”The connection to adb is down, and a severe error has occured“问题
- android 出现The connection to adb is down, and a severe error has occured.问题解决
- Resolution to the record count increasing of the file exported from DB when ‘0A’ is included in it
- 解决问题:Cannot refer to the non-final local variable user defined in an enclosing scope
- android中 the connection to adb is down,问题解决
- 关于Eclipse与Genymotion连接时报错“The connection to adb is down, and a severe error has occured.”的解决办法