Search code examples
databaseasp-classicrecordset

Asp-Classic ADODB Recordset missing Records


one of the simplest Components in my website just stopped working from one day to the other without any changes in Code.

'Connection Declaration as connection
Set rs = Server.CreateObject ("ADODB.Recordset")
rs.Open "SELECT * FROM tablename ORDER BY id DESC", connection, 1, 3
while not rs.EOF
  'writing some Table from the records in DB
  'Simplified Code %>
  <tr><td><%=rs("id")%></td><td><%=rs("description")&></td></tr>
  <%
  rs.MoveNext
Wend

in my Database i have verified the extraordinary number of 30 records :(

when above code is executed i see 2 of them

This tells me two things,

first: the tablename is Correct and the connection to the Database is established
second: the table-generation in itself is correct

I also have a smaller Testing-System. there the exact same code on a sample Database produces the expected Results.

Unfortunately i have no means of "instant-access" to my main page for "debugging purposes"

Is there any known Bugs for ADODB Recordsets losing records? Please keep in mind the Code is exactly the same and working "error-free".


Solution

  • A few suggestions.

    Use Option Explicit if not already - (I didn't see it in your code) this will display SQL errors, so that may help.

    Check that you haven't destroyed RS.

    Also, "connection, 1, 3" means 'active connection', 'cursortype', 'locktype'

    Your cursortype is 'adOpenKeySet' - 3 or 'adOpenStatic' is better, unless you specifically want a KeySet? try calling the Open this way to force the defaults (which oddly enough are 3 and 1 respectively !) :

    RS.Open "SELECT * FROM tablename ORDER BY id DESC",connection 
    

    I also usually write RS output loops like this :

    If Not RS.BOF Then
       ' write table tag HTML
       Do While Not RS.EOF
          ' write table row + row data
          RS.MoveNext
       Loop
       ' write end table tag HTML
    Else
       ' write "RS is empty!"
    End If
    

    This will make it easier to tell if recordset is empty or not.