ADODB.字段错误“80020009”

问题描述 投票:0回答:1

最近我们经常遇到这样的错误: ADODB.字段错误“80020009”

BOF 或 EOF 为 True,或者当前记录已被删除。请求的操作需要当前记录。

/PHET/mscripts/TestScoring.asp, line 52 

此特定文件用于其他 10 项测试,并且这些测试都没有出错。我检查了数据库,一切看起来都很好。这是引发错误的实际页面...

<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="DoSecure.asp" -->
<!--#include virtual="/lib/dbConnModules.asp" -->
<%
Dim rsAnswer__MMColParam
rsAnswer__MMColParam = Session("ModuleID")
Set rsAnswer = Server.CreateObject("ADODB.Recordset")
rsStrAnswer = "SELECT * FROM TestAnswers WHERE TestName = '" & Request.Form("testName") & "' and ApplicationID = '" & Session("ApplicationID") & "' and moduleID = '" + Replace(rsAnswer__MMColParam, "'", "''") + "'"
rsAnswer.open rsStrAnswer, dbConnModules
answerArray = array(rsAnswer("AnswerQ1"), rsAnswer("AnswerQ2"), rsAnswer("AnswerQ3"), rsAnswer("AnswerQ4"), rsAnswer("AnswerQ5"), rsAnswer("AnswerQ6"), rsAnswer("AnswerQ7"), rsAnswer("AnswerQ8"), rsAnswer("AnswerQ9"), rsAnswer("AnswerQ10"), rsAnswer("AnswerQ11"), rsAnswer("AnswerQ12"), rsAnswer("AnswerQ13"), rsAnswer("AnswerQ14"), rsAnswer("AnswerQ15"), rsAnswer("AnswerQ16"), rsAnswer("AnswerQ17"), rsAnswer("AnswerQ18"), rsAnswer("AnswerQ19"), rsAnswer("AnswerQ20"))
testArray = array(Request.Form("Q1"), Request.Form("Q2"), Request.Form("Q3"), Request.Form("Q4"), Request.Form("Q5"), Request.Form("Q6"), Request.Form("Q7"), Request.Form("Q8"), Request.Form("Q9"), Request.Form("Q10"), Request.Form("Q11"), Request.Form("Q12"), Request.Form("Q13"), Request.Form("Q14"), Request.Form("Q15"), Request.Form("Q16"), Request.Form("Q17"), Request.Form("Q18"), Request.Form("Q19"), Request.Form("Q20"))
if not rsAnswer.EOF then
    myCorrect = 0
    For i=0 To (rsAnswer("NumOfQs") - 1)
        'Response.Write(i+1 & Request.Form("q" & i+1) & "<br />")
        If isNull(answerArray(i)) then answerArray(i) = "" End If
        If answerArray(i) = testArray(i) Then
            myCorrect = myCorrect + 1
        End if
    Next
    'Response.Write(myCorrect)
end if  
'Response.Write(myCorrect)
%>
<%
strTestRecord = "insert into TestRecords (ApplicationID, ModuleID, TestName, UserEmail, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, Q10, Q11, Q12, Q13, Q14, Q15, Q16, Q17, Q18, Q19, Q20, Debugger, numberCorrect) values ('" &_ 
        Session("ApplicationID") & "', '"&_
        Session("ModuleID") & "', '"&_
        Replace(Request.Form("testName"), "'", "''") & "', '"&_
        Session("UserEmailAddr") & "', '"&_
        Replace(Request.Form("Q1"), "'", "''") & "', '" &_
        Replace(Request.Form("Q2"), "'", "''") & "', '" &_
        Replace(Request.Form("Q3"), "'", "''") & "', '" &_
        Replace(Request.Form("Q4"), "'", "''") & "', '" &_
        Replace(Request.Form("Q5"), "'", "''") & "', '" &_
        Replace(Request.Form("Q6"), "'", "''") & "', '" &_
        Replace(Request.Form("Q7"), "'", "''") & "', '" &_
        Replace(Request.Form("Q8"), "'", "''") & "', '" &_
        Replace(Request.Form("Q9"), "'", "''") & "', '" &_
        Replace(Request.Form("Q10"), "'", "''") & "', '" &_
        Replace(Request.Form("Q11"), "'", "''") & "', '" &_
        Replace(Request.Form("Q12"), "'", "''") & "', '" &_
        Replace(Request.Form("Q13"), "'", "''") & "', '" &_
        Replace(Request.Form("Q14"), "'", "''") & "', '" &_
        Replace(Request.Form("Q15"), "'", "''") & "', '" &_
        Replace(Request.Form("Q16"), "'", "''") & "', '" &_
        Replace(Request.Form("Q17"), "'", "''") & "', '" &_
        Replace(Request.Form("Q18"), "'", "''") & "', '" &_
        Replace(Request.Form("Q19"), "'", "''") & "', '" &_
        Replace(Request.Form("Q20"), "'", "''") & "', '" &_
        Request.Form("Debugger") & "', " & myCorrect & ")"      
Session("NumOfQs") = rsAnswer("NumOfQs")
Session("NumToPass") = rsAnswer("NumToPass")

Session("YourScore") = myCorrect

if myCorrect > Session("NumToPass") then pf = "pass" else pf = "fail" end if ' PASS OR FAIL
strTestRecordComplete = "insert into CheckRequirements (ApplicationID, UserEmail, ModuleID, RequirementName, PassOrFail, OperationalIPAddr) values ('" & Session("ApplicationID") & "', '" & Session("UserEmailAddr") & "', '" & Session("ModuleID") & "', '"& Request.Form("testName") & "', '" & pf & "', '" & Request.ServerVariables("REMOTE_ADDR") & "')"
dbConnModules.Execute(strTestRecord)
dbConnModules.Execute(strTestRecordComplete)
if Request.Form("TestName") = "pretest" Then
    Response.Redirect("../" & Session("ModuleDir") & "/TestResults.asp?fr=pre&desturl="& Request.Form("desturl"))
elseif Request.Form("TestName") = "posttest" Then
    Session("rsYourAnswers") = testArray
    Response.Redirect("../" & Session("ModuleDir") & "/TestResults.asp?fr=post&desturl="& Request.Form("desturl"))
End If
%>
<%
rsAnswer.Close()
Set rsAnswer = Nothing
%>
<!--#include virtual="/lib/dbConnModulesClose.asp" -->

有什么想法吗?谢谢。

asp-classic
1个回答
0
投票

您在两个位置访问记录集,而不检查它是否包含任何记录。只需将访问记录集的代码移至您已有的条件即可:

rsAnswer.open rsStrAnswer, dbConnModules
testArray = array(Request.Form("Q1"), Request.Form("Q2"), Request.Form("Q3"), Request.Form("Q4"), Request.Form("Q5"), Request.Form("Q6"), Request.Form("Q7"), Request.Form("Q8"), Request.Form("Q9"), Request.Form("Q10"), Request.Form("Q11"), Request.Form("Q12"), Request.Form("Q13"), Request.Form("Q14"), Request.Form("Q15"), Request.Form("Q16"), Request.Form("Q17"), Request.Form("Q18"), Request.Form("Q19"), Request.Form("Q20"))
if not rsAnswer.EOF then
    answerArray = array(rsAnswer("AnswerQ1"), rsAnswer("AnswerQ2"), rsAnswer("AnswerQ3"), rsAnswer("AnswerQ4"), rsAnswer("AnswerQ5"), rsAnswer("AnswerQ6"), rsAnswer("AnswerQ7"), rsAnswer("AnswerQ8"), rsAnswer("AnswerQ9"), rsAnswer("AnswerQ10"), rsAnswer("AnswerQ11"), rsAnswer("AnswerQ12"), rsAnswer("AnswerQ13"), rsAnswer("AnswerQ14"), rsAnswer("AnswerQ15"), rsAnswer("AnswerQ16"), rsAnswer("AnswerQ17"), rsAnswer("AnswerQ18"), rsAnswer("AnswerQ19"), rsAnswer("AnswerQ20"))
    myCorrect = 0
    For i=0 To (rsAnswer("NumOfQs") - 1)
        'Response.Write(i+1 & Request.Form("q" & i+1) & "<br />")
        If isNull(answerArray(i)) then answerArray(i) = "" End If
        If answerArray(i) = testArray(i) Then
            myCorrect = myCorrect + 1
        End if
    Next
    'Response.Write(myCorrect)
    Session("NumOfQs") = rsAnswer("NumOfQs")
    Session("NumToPass") = rsAnswer("NumToPass")
Else  
    Session("NumOfQs") = 0
    Session("NumToPass") = 0
End If

请记住从原始代码末尾删除这两行:

Session("NumOfQs") = rsAnswer("NumOfQs")
Session("NumToPass") = rsAnswer("NumToPass")

因为它现在已添加到“主”块中。

© www.soinside.com 2019 - 2024. All rights reserved.