Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Receiving the error "There is already an open DataReader associated with this Command which must be closed first." [solved]

Receiving the error "There is already an open DataReader associated with this Command which must be closed first." [solved]

Scheduled Pinned Locked Moved Visual Basic
designhelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Marcus J Smith
    wrote on last edited by
    #1

    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

    B 1 Reply Last reply
    0
    • M Marcus J Smith

      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

      B Offline
      B Offline
      Ben Fair
      wrote on last edited by
      #2

      The message means exactly what is says; there is a DataReader created from the command's ExecuteReader() 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 a finally block, so maybe you inserted code to re-use a command object inside a try block where a DataReader is created from the command's ExecuteReader() function and has not been closed since the finally block hasn't executed.

      Keep It Simple Stupid! (KISS)

      M 1 Reply Last reply
      0
      • B Ben Fair

        The message means exactly what is says; there is a DataReader created from the command's ExecuteReader() 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 a finally block, so maybe you inserted code to re-use a command object inside a try block where a DataReader is created from the command's ExecuteReader() function and has not been closed since the finally block hasn't executed.

        Keep It Simple Stupid! (KISS)

        M Offline
        M Offline
        Marcus J Smith
        wrote on last edited by
        #3

        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)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups