CFF KB - Carrz-Fox-Fire Promotions Knowledge Base

CFF KB is all about 1 thing: The Sharing of Knowledge and the Power we gain from it.
  • Breadrumbs:
  • Invalid attempt to call MetaData when reader is closed.

  • CFF Knowledge Base - Share With Facebook CFF Knowledge Base - Share on Twitter CFF Knowledge Base - Share on Reddit CFF Knowledge Base - Share on Digg It CFF Knowledge Base - Share on Stumble Upon It CFF Knowledge Base - Share on Delicious
    Share With Friends (Updated 6-8-2010)
  • Article ID:
    7287
  • Date Created
    Sunday, May 25, 2025
  • Last Updated
    Sunday, May 25, 2025
  • This Article Has been Viewed
    0 times
  • Short Desc
    When trying to use a closed recordset, this error will appear: "Invalid attempt to call MetaData when reader is closed."
  • Details
    When closing a datareader or dataset, you cannot use the recordset unless you create a Global Variable to use instead.
  • Recreate Issue
    Using the following code will reproduce the error.

    If rs1.Read() Then
    dim theRecord as Integer = rs1("AlbumArtistID")
    End If
    rs1.Close()

    Then use this down the page.
    getAlbumID.Parameters.Add(New SqlParameter("@ID", rs1("ID")))

  • Resolve Issue
    If you are going to close your Reader / Dataset and intend to make a call to the record, you will need to create a Global Variable.

    Do the following.

    Public Class GlobalVariables
    Public Shared theRecord As Integer
    End Class

    If rs1.Read() Then
    GlobalVariables.theRecord = rs1("AlbumArtistID")
    End If
    rs1.Close()