ASP Error ‘80020009’

Again today, I came across an error caused by an invalid date value. The error reported was:

  1. error '80020009'
  2. Exception occurred.
  3. /somefile.asp, line <number>

Went and googled again, this time it appeared as though the error was commonly caused by over-stepping the bounds of the resultset. For instance, pulling back 10 records by trying to read the 11th which doesn’t exist. Well that wasn’t the case for mine (once again), it was an invalid date format.

All I was doing, was displaying the date value. I wasn’t using it to do any calculations in either ASP or through SQL, so even it if was invalid, you would assume it would just ‘display it’ and be done with it.

For whatever reason, just trying to display a date of format ‘0000-01-04’ caused it to fall over. The solution of course, just correct the date value. Once again, lack of client and server side checking of user input bites you in the arse.

11 thoughts on “ASP Error ‘80020009’

  1. To be brutally honest menka, I don’t know. I’ve mentioned before that the error reporting from ASP, has a lot to be desired. They use the same error code for many many different errors; when in fact the errors (after my investigations at least), seem wildly different.

    You need to whittle down the error, narrowing the possibilities each time.

    What are you doing when you get the error? Are you using a database for instance, is the error happening when accessing a resultset from a query, is it something else?

    You would need to give me some insight for me to be able to help you at all.

  2. Thanks,
    Although my problem wasn’t an invalid date value, your explaination helped. My problem was actually caused by over-stepping the bounds of the resultset. I just hadn’t thought of that.

  3. when i m trying to retrive more records from oracle database using asp page its showing exception error

  4. There is no reason for ASP to generate that error, simply because you’ve selected more than one record. It is more likely that you’re accessing the records incorrectly. A simple method to make sure you don’t ever overstep the resultset is:

    1. Dim cn, sSQL, oRS
    2. Set cn = Server.CreateObject("ADODB.Connection")
    3. cn.Open sDSN
    4. sSQL = "SELECT field FROM table_name WHERE something = 1"
    5. Set oRS = cn.execute(sSQL)
    6. If Not oRS.EOF Then
    7. While Not oRS.EOF
    8. Response.Write "field=" & oRS("field")
    9. oRS.MoveNext
    10. WEnd
    11. oRS.Close
    12. End If
    13. cn.Close
    14. Set oRS = Nothing
    15. Set cn = Nothing

    Using the above method, you’ll never overstep the resultset. The reason this won’t happen is the Not oRS.EOF condition. So you will only ever go into the While loop if the current read position in the recordset isn’t the last record in the set.

  5. Just googled upon this as I was getting the same error. However, I have a slightly different scenario. Essentially I load data into a Dictionary object to be displayed further along in the processing, like so:


    oDict.Add key, rs.Fields( fieldname )

    Set rs = Nothing

    Response.Write oDict( key ) ‘ Error occurs here

    The problem is I have blindly assumed that the VALUE of rs.Fields( fieldname ) will be added to the dictionary, when in fact a REFERENCE to the Field object is being added, which of course went out of scope the moment I set the parent ResultSet to Nothing.

  6. Chris,

    As with every language, you will nearly always have scoping problems at some point. The trick is knowing how your particular language scopes variables. I thought VBScript passed/assigned using a ByVal method instead of ByRef by default, I’ll have to look into that jus to clarify for myself.

    Al.

  7. I am having a similar problem and getting the error as follows:

    50 FAQs This shows that faqnum.Count is returning the correct value
    error ‘80020009’ Trying to read faqnum.Item(faq) where faq = 1
    /spfaq.asp, line 87
    The dictionary object in loaded from a database using Set rsFAQs = Server… and I have left rsFAQs open afterwards.
    Any help is gratefully received.

  8. I recently had the same problem using the Dictionary object.

    You can fix this error by casting your key into String. Don’t know why, but it will fix the problem on Error ‘80020009’.

    Fix this by putting (example) :
    Response.Write oDict(CStr(key))

  9. Is there any reason you can think of that the error would ONLY occur in IE6? Firefox, Safari, Mac, PC doesn’t seem to matter… but IE6 shows that error.

    I’m completely stumped. Server-side errors shouldn’t matter what browser the user has.

Comments are closed.