Server Error in '/' Application.
--------------------------------------------------------------------------------
Invalid attempt to read when no data is present.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Invalid attempt to read when no data is present.
Source Error:
Line 322: dr.Read()
Line 323:
Line 324: Response.Write(dr("Quote"))
Line 325: Response.Write(dr("Name"))
Line 326:
This Error is INCONSISTENT. If the page is refreshed say 10 times, it may give the error 4 out of 9 times.Code:Sub Random_Quote() Dim conDB As SqlConnection = New SqlConnection("Server=DOX;Database=integration;User ID=sa;Password=x") Dim dr As SqlDataReader Dim RecNo, MaxRecNo, MinRecNo as Integer conDB.Open() Dim cmdSelectRndmQuote As SqlCommand = New SqlCommand( "Select Max(ID) as MaxID, Min(ID) as MinID FROM dbo.tblQuotes", conDB) dr = cmdSelectRndmQuote.ExecuteReader() dr.Read() MaxRecNo = Int(dr("MaxID")) MinRecNo = Int(dr("MinID")) RecNo = getRandomNumber(MinRecNo,MaxRecNo) dr.Close() cmdSelectRndmQuote = New SqlCommand( "SELECT dbo.tblQuotes.ID, dbo.tblQuotes.Quote, dbo.tblTextSource.Name, dbo.tblTextSource.Nlink FROM dbo.tblTextSource RIGHT JOIN dbo.tblQuotes ON dbo.tblTextSource.ID = dbo.tblQuotes.Source WHERE dbo.tblQuotes.ID = '" & RecNo & "'", conDB) dr = cmdSelectRndmQuote.ExecuteReader() dr.Read() Response.Write(dr("Quote")) Response.Write(dr("Name")) dr.Close() conDB.Close() conDB.Dispose() End Sub


Reply With Quote
Bookmarks