有效响应导致 "Subcript out of range"
Valid response causes "Subcript out of range"
我有一个经典的 ASP 应用程序,它联系数据库并收到有效响应,但随后崩溃
Error Number 9: Subscript out of range
退出 IF
块后,将进行数据库调用。奇怪的是,相同的代码当前正在生产中运行。据我所知,它们的配置相同(但我怀疑存在导致此问题的细微差别)并且具有相同的代码库。
我想知道的是:
- 据称我试图访问其不存在的索引的数组在哪里?我没有看到它,错误没有给出行号。 adodb 库中是否有可能无法正常工作?
- 也许这是与某个补丁和我的特定数据库连接库有关的常见问题?你有过类似的经历吗?
- 如何解决没有立即出现的问题?我是否应该开始将故障排除语句放入库中?
代码中发生的事情的解释:收到 cookie "click" 时,err.number
为 0。收到 cookie "bang" 时,err.number
为 9。然后它在 IF
块的末尾因该错误而崩溃。
<%@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
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?
这是你的数组:
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.
可能是您的区域设置不同?
我强烈建议您使用更好的错误处理。
Internal Server Error 500 w/ IIS Log
要调试,请添加这样的语句
Response.Write (objRS("latestDate"))
行前
latestDate = calConvertDate(objRS("latestDate"))
因此您可以查看(例如)从服务器返回的日期是否使用“-”作为分隔符而不是“/”,或者是否返回空值。
了解问题原因后即可解决
我有一个经典的 ASP 应用程序,它联系数据库并收到有效响应,但随后崩溃
Error Number 9: Subscript out of range
退出 IF
块后,将进行数据库调用。奇怪的是,相同的代码当前正在生产中运行。据我所知,它们的配置相同(但我怀疑存在导致此问题的细微差别)并且具有相同的代码库。
我想知道的是:
- 据称我试图访问其不存在的索引的数组在哪里?我没有看到它,错误没有给出行号。 adodb 库中是否有可能无法正常工作?
- 也许这是与某个补丁和我的特定数据库连接库有关的常见问题?你有过类似的经历吗?
- 如何解决没有立即出现的问题?我是否应该开始将故障排除语句放入库中?
代码中发生的事情的解释:收到 cookie "click" 时,err.number
为 0。收到 cookie "bang" 时,err.number
为 9。然后它在 IF
块的末尾因该错误而崩溃。
<%@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
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?
这是你的数组:
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.
可能是您的区域设置不同?
我强烈建议您使用更好的错误处理。 Internal Server Error 500 w/ IIS Log
要调试,请添加这样的语句
Response.Write (objRS("latestDate"))
行前
latestDate = calConvertDate(objRS("latestDate"))
因此您可以查看(例如)从服务器返回的日期是否使用“-”作为分隔符而不是“/”,或者是否返回空值。
了解问题原因后即可解决