Receiving the error "There is already an open DataReader associated with this Command which must be closed first." [solved]
-
I am working to add some additional functionality to a project and without changing anything to a particular form and DataSet object I began getting the error "There is already an open DataReader associated with this Command which must be closed first.". I am using a DataSet object that is actually part of the project which contains 2 datatables. I fill one for a large datagridview and fill the other table based on the row selection in the first. This has been working fine until today. I have already tried the "MultipleActiveResultSets=true;" parameter in the connection string and it makes no difference. Resolution: I just began setting the Dataset connection programmatically to override what was set at design time. I was using the same connection for both table adapters and after letting Ben's response sink in I realized what I was doing. Thanks!
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
modified on Tuesday, November 25, 2008 2:57 PM
-
I am working to add some additional functionality to a project and without changing anything to a particular form and DataSet object I began getting the error "There is already an open DataReader associated with this Command which must be closed first.". I am using a DataSet object that is actually part of the project which contains 2 datatables. I fill one for a large datagridview and fill the other table based on the row selection in the first. This has been working fine until today. I have already tried the "MultipleActiveResultSets=true;" parameter in the connection string and it makes no difference. Resolution: I just began setting the Dataset connection programmatically to override what was set at design time. I was using the same connection for both table adapters and after letting Ben's response sink in I realized what I was doing. Thanks!
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
modified on Tuesday, November 25, 2008 2:57 PM
The message means exactly what is says; there is a
DataReader
created from the command'sExecuteReader()
function that has not been closed. You'll have to trace through the code, find it and close it. I think it's common for this kind of thing to be done in afinally
block, so maybe you inserted code to re-use a command object inside atry
block where aDataReader
is created from the command'sExecuteReader()
function and has not been closed since thefinally
block hasn't executed.Keep It Simple Stupid! (KISS)
-
The message means exactly what is says; there is a
DataReader
created from the command'sExecuteReader()
function that has not been closed. You'll have to trace through the code, find it and close it. I think it's common for this kind of thing to be done in afinally
block, so maybe you inserted code to re-use a command object inside atry
block where aDataReader
is created from the command'sExecuteReader()
function and has not been closed since thefinally
block hasn't executed.Keep It Simple Stupid! (KISS)
If it was the code I wrote I would have all of that done but all I am doing is calling a TableDataAdapter that is created from the .NET Dataset to fill the local datatable contained in my instance of that dataset. As I said before, this was not an issue, I did not change anything and am now having to track it down. Here is the code where it breaks.
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _ Global.System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter"), _ Global.System.ComponentModel.DataObjectMethodAttribute(Global.System.ComponentModel.DataObjectMethodType.Fill, false)> _ Public Overloads Overridable Function GetCustomerDetailsCustomerDetailID(ByVal dataTable As CustomerDetail.CustomerDetailsDataTable, ByVal CustomerDetailID As Global.System.Nullable(Of Integer)) As Integer Me.Adapter.SelectCommand = Me.CommandCollection(1) If (CustomerDetailID.HasValue = true) Then Me.Adapter.SelectCommand.Parameters(1).Value = CType(CustomerDetailID.Value,Integer) Else Me.Adapter.SelectCommand.Parameters(1).Value = Global.System.DBNull.Value End If If (Me.ClearBeforeFill = true) Then dataTable.Clear End If Dim returnValue As Integer = Me.Adapter.Fill(dataTable) Return returnValue End Function
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)