broguesquadron
broguesquadron

Reputation: 35

Valid response causes "Subcript out of range"

I've got a classic ASP application that contacts a database and receives a valid response but then crashes with

Error Number 9: Subscript out of range

after exiting the IF block the db call is made in. What's odd is that the same code is currently working in production. As far as I can tell they're configured identically (but I suspect there's a subtle difference that's causing this issue) and have identical code bases.

What I want to know is:

  1. Where is this array that I'm supposedly attempting to reach a non-existent index of? I don't see it and the error gives no line number. Is there a chance something is not working correctly in the adodb library?
  2. Perhaps this is a common problem having to do with a certain patch and my particular db connection library? Have you had a similar experience?
  3. How do I troubleshoot a problem that doesn't immediately present itself? Should I just start putting troubleshooting statements in the library?

Explanation of what's happening in the code: When the cookie "click" is received err.number is 0. When the cookie "bang" is received the err.number is 9. It then crashes with that error at the end of the IF block.

<%@Language="VBSCRIPT"%>
<% Server.ScriptTimeout = 150 %> 
<%
On Error resume Next
%>
<!--#include file="adovbs.inc"-->
<!--#INCLUDE FILE="DBConn.asp"-->
<!--#INCLUDE FILE="ErrorHandler.asp"--> 
<%

'Application Timeout Warning
sessionTimeout = 20
advanceWarning = 5
jsTimeout = (sessionTimeout - advanceWarning) * 60000

'If the users session has expired
If Session("USERNAME") = "" or Session("USERNAME") = NULL Then
    Response.Redirect("default.asp")
End If
'If the user has just changed their password.  Prompt them that it was successfully changed
If Request("changePasswd") = "true" Then
    Response.Write("<script language='Javascript'>alert('Your Password Has been Successfully Changed!');</script>")
End If

Dim connection, cmd, objRS, latestDate, lastDateJPMC, firstDateJPMC, lastDateWACH, firstDateWACH, lastDateWFB, firstDateWFB, accountCount

Function calConvertDate(theDate)
    Dim yr, mn, dy, dtSplit
    dtSplit = Split(theDate,"/")
    yr = dtSplit(2)
    mn = dtSplit(0)
    dy = dtSplit(1)

    if Len(mn) = 1 then mn = "0" & mn
    if Len(dy) = 1 then dy = "0" & dy

    calConvertDate = "[" & yr & "," & mn & "]"
End Function

set connection = Server.CreateObject("adodb.connection")
connection.Open DBConn
connection.CommandTimeout = 60   
set connection = Server.CreateObject("adodb.connection")
connection.Open DBConn    
connection.CommandTimeout = 60  
'Get Earliest & Latest Date in Database

If Err.Number = 0 Then
            Response.Cookies("CLICK")=Err.number
    Set cmd = Server.CreateObject("ADODB.Command")    
    With cmd
        Set .ActiveConnection = connection
        .CommandText = "CIRS_Admin.spGetLatestDate"
        .CommandType = adCmdStoredProc
        set objRS = .Execute
    End With

    latestDate = calConvertDate(objRS("latestDate"))
        Response.Cookies("latestdate")=objRS("latestDate")
    objRS.Close
    Set objRS = Nothing
        Response.Cookies("BANG")=Err.number
End If

Upvotes: 0

Views: 95

Answers (2)

Enrico Di Cesare
Enrico Di Cesare

Reputation: 41

To debug, please add a statement like

Response.Write (objRS("latestDate"))

before the line

latestDate = calConvertDate(objRS("latestDate"))

so you can see if (for example) the date returned from the server has "-" as separator instead of "/" or if an empty value is returned.

After understanding what is causing the problem you can solve it

Upvotes: 1

Zam
Zam

Reputation: 2940

1.Where is this array that I'm supposedly attempting to reach a non-existent index of? I don't see it and the error gives no line number. Is there a chance something is not working correctly in the adodb library?

This is your array:

yr = dtSplit(2)
mn = dtSplit(0)
dy = dtSplit(1)

What's odd is that the same code is currently working in production. As far as I can tell they're configured identically (but I suspect there's a subtle difference that's causing this issue) and have identical code bases.

May be you have different regional settings?

I strongly suggest to you use better error handling. Internal Server Error 500 w/ IIS Log

Upvotes: 0

Related Questions