System.InvalidOperationException: 已有打开的与此命令相关联的 DataReader,必须首先将它关闭。 在 System.Data.SqlClient.SqlInternalConnectionTds.ValidateConnectionForExecute(SqlCommand command) 在 System.Data.SqlClient.SqlConnection.ValidateConnectionForExecute(String method, SqlCommand command) 在 System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async) 在 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) 在 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) 在 System.Data.SqlClient.SqlCommand.ExecuteScalar() 在 _Default.TreeViewBind() 位置 c:\treeview\Default.aspx.cs:行号 40
错误如上:
已有打开的与此命令相关联的 DataReader,必须首先将它关闭
同时打开建立两个DataReader,而采用同一个SqlConnection;
解决方法: 两个DataReader用不同的SqlConnection;
注意: DataReader依托于SqlConnection,如果SqlConnection关闭了,DataReader也就自动消亡了
另外DataReader在使用时不能关闭SqlConnection
相关文章:
-
2022-12-23
-
2022-12-23
-
2022-12-23
-
2021-12-03
-
2021-08-29
-
2021-11-17
-
2022-12-23
猜你喜欢
-
2021-10-17
-
2022-01-04
-
2021-12-27
-
2022-12-23
-
2021-09-08
相关资源
-
下载
2023-03-02
-
下载
2023-03-12
-
下载
2021-06-05
-
下载
2022-12-09
-
下载
2021-07-01