|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
object open error...cant locate the exact open connection
Error Type:
ADODB.Recordset (0x800A0E79) Operation is not allowed when the object is open. /eass/common/test/2004s1/start_check.asp, line 85 Code:
<!-- #include file="../../../database/connection.asp" -->
<%
dim checkMaxAttempt,checkScore1,checkScore2
checkMaxAttempt = 0
checkScore1 = 0
checkScore2 = 0
Session("Paper") = "2004S1"
'--------------------------------------------------------------------------
' Set the SQL query search for studentID from database
'--------------------------------------------------------------------------
strSQL = "Select * FROM Attempts WHERE (studentID = '" & Session("StudID") & "') AND (Paper ='"& Session("Paper") &"')"
objRst.Open strSQL, objConn
If objRst.EOF <> FALSE Then ' No attempts record
'--------------------------------------------------------------------------
' set them 3 attempts and a new time.
'--------------------------------------------------------------------------
strSQL = "INSERT INTO Attempts (StudentID,Paper,MaxAttempts,Hrs,Mins,Secs)"
strSQL = strSQL & "VALUES"
strSQL = strSQL & "('"& Session("StudID") & "',"
strSQL = strSQL & "'" & Session("Paper") & "',"
strSQL = strSQL & " " & 3 & ","
strSQL = strSQL & " " & 2 & ","
strSQL = strSQL & " " & 0 & ","
strSQL = strSQL & " " & 0 & ")"
objConn.Execute (strSQL)
strSQL = "INSERT INTO 2004S1_Score (StudentID)"
strSQL = strSQL & "VALUES"
strSQL = strSQL & "('"& Session("StudID") & "')"
objConn.Execute (strSQL)
Else
objRst.Close
'--------------------------------------------------------------------------
' check for score records
'--------------------------------------------------------------------------
strSQL = "Select * FROM 2004S1_Score WHERE (studentID = '" & Session("StudID") & "')"
objRst.Open strSQL, objConn
checkScore1= objRst("S12004_Score1")
checkScore2= objRst("S12004_Score2")
objRst.Close
'--------------------------------------------------------------------------
' only allows 2nd and 3rd attempts if only scored less than 70%
'--------------------------------------------------------------------------
strSQL = "Select * FROM Attempts WHERE (studentID = '" & Session("StudID") & "') AND (Paper ='"& Session("Paper") &"')"
objRst.Open strSQL, objConn
checkMaxAttempt = objRst("MaxAttempts")
objRst.Close
If checkMaxAttempt = "2" AND checkScore1 >= "70" Then
response.redirect "error.asp"
ElseIf checkMaxAttempt <= "1" AND checkScore2 >= "70" Then
response.redirect "error.asp"
ElseIf checkMaxAttempt <= "0" Then
response.redirect "error.asp"
Else 'do nothing
End If
End If
'--------------------------------------------------------------------------
' update # of attempts
'--------------------------------------------------------------------------
strSQL = "Select * FROM Attempts WHERE (studentID = '" & Session("StudID") & "') AND (Paper ='"& Session("Paper") &"')"
objRst.Open strSQL, objConn
checkMaxAttempt = objRst("MaxAttempts")
checkMaxAttempt = checkMaxAttempt - 1
objRst.close
Set objRst = Nothing
strSQL="Update Attempts SET MaxAttempts = "& checkMaxAttempt &" WHERE (studentID = '" & Session("StudID") & "') AND (Paper ='"& Session("Paper") &"')"
objConn.Execute (strSQL)
objConn.Close
Set objConn = Nothing
response.redirect "q12.asp"
%>
|
|
#2
|
||||
|
||||
|
Hi,
your objRst only closes in the Else of the first if is executed, put a objRst.Close, before you create the new recordset Code:
objRst.Close
strSQL = "Select * FROM Attempts WHERE (studentID = '" & Session("StudID") & "') AND (Paper ='"& Session("Paper") &"')"
objRst.Open strSQL, objConn
Hope this helps
__________________
Look! Its a ShemZilla ![]() ![]()
|
|
#3
|
|||
|
|||
|
Quote:
hi, after closed it , it gave me annother error
|
|
#4
|
||||
|
||||
|
Hi, ok delete the previous .Close and put one in your if statement
Code:
If objRst.EOF <> FALSE Then ' No attempts record
'--------------------------------------------------------------------------
' set them 3 attempts and a new time.
'--------------------------------------------------------------------------
strSQL = "INSERT INTO Attempts (StudentID,Paper,MaxAttempts,Hrs,Mins,Secs)"
strSQL = strSQL & "VALUES"
strSQL = strSQL & "('"& Session("StudID") & "',"
strSQL = strSQL & "'" & Session("Paper") & "',"
strSQL = strSQL & " " & 3 & ","
strSQL = strSQL & " " & 2 & ","
strSQL = strSQL & " " & 0 & ","
strSQL = strSQL & " " & 0 & ")"
objConn.Execute (strSQL)
strSQL = "INSERT INTO 2004S1_Score (StudentID)"
strSQL = strSQL & "VALUES"
strSQL = strSQL & "('"& Session("StudID") & "')"
objConn.Execute (strSQL)
objRst.Close
Else
objRst.Close
'--------------------------------------------------------------------------
' check for score records
'--------------------------------------------------------------------------
strSQL = "Select * FROM 2004S1_Score WHERE (studentID = '" & Session("StudID") & "')"
objRst.Open strSQL, objConn
checkScore1= objRst("S12004_Score1")
checkScore2= objRst("S12004_Score2")
objRst.Close
'--------------------------------------------------------------------------
' only allows 2nd and 3rd attempts if only scored less than 70%
'--------------------------------------------------------------------------
strSQL = "Select * FROM Attempts WHERE (studentID = '" & Session("StudID") & "') AND (Paper ='"& Session("Paper") &"')"
objRst.Open strSQL, objConn
checkMaxAttempt = objRst("MaxAttempts")
objRst.Close
If checkMaxAttempt = "2" AND checkScore1 >= "70" Then
response.redirect "error.asp"
ElseIf checkMaxAttempt <= "1" AND checkScore2 >= "70" Then
response.redirect "error.asp"
ElseIf checkMaxAttempt <= "0" Then
response.redirect "error.asp"
Else 'do nothing
End If
End If
hope this helps |
|
#5
|
|||
|
|||
|
Quote:
thanks it worked! btw, you should only set objconn.close and set objconn = nothing in the very end of ur asp file if they are few sql insert or update statenment objConn.Execute (strSQL)? and when u use objrst.close, it is u set objrst = nothing after it immediately or only just need it in the very end of asp file too ? |
|
#6
|
||||
|
||||
|
Well, that is a good question
![]() I would say its good standards to close you rs and conn as soon as you are done with the processing of it. And at the end of the database interaction, set both of them to nothing. I don't know if there is a DO and DONT, but one thing is for sure, you have to close your objects when you are done with them, and set them to nothing before you leave the page aswell. Glad its working now! ![]() |
![]() |
| Viewing: ASP Free Forums > Programming > ASP Development > object open error...cant locate the exact open connection |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|