Re: operation not allowed when object is open

From: Luqman (pearlsoft_at_cyber.net.pk)
Date: 12/28/04


Date: Tue, 28 Dec 2004 15:25:37 +0500

Close the Recordset before open with the following.

If Rst.State=1 then
Rst.Close
End If

Rst.Open strSqlRst,Conn,2,2 'adOpenDynamic,adLockPessimistic

Best Regards,

Luqman

"hengzhe" <hengzhe@discussions.microsoft.com> wrote in message
news:430B95C9-00A4-4930-AFC7-4A7477E3C8E1@microsoft.com...
> The following code worked fine when there were only few concidential
> requests(eg.,no more than 10)but an error was encountered while
> concidential
> requests increased(eg.more than 10 people opened the page concurrently).
> the error reported was:
> Operation not allowed when object is open
> using my error handling mechanism,I can decided that the error occured in
> Rst.Open strSqlRst,Conn,2,2
> but I don't the reason for this.
> Any suggestion would be greatly appreciated, thanks in advance.
>
> Dim aryTableName(2),I,J
> aryTableName(1) = "table1"
> aryTableName(2) ="table2"
> Set Rst = Server.CreateObject("Adodb.RecordSet")
> Conn.BeginTrans
> If blnUseSbjTable Then
> J = 2
> Else
> J = 1
> End If
> For I = 1 To J
> strSqlRst = "Select * From [" & aryTableName(I)
> strSqlRst = strSqlRst & "] Where Student_ID='" & strStuId & "'"
> Rst.Open strSqlRst,Conn,2,2 'adOpenDynamic,adLockPessimistic
> 'error handling
> fnCheckError "Openning[" & aryTableName(I) & "]"
> If Rst.EOF Then
> Rst.AddNew
> End If
> Rst("student_ID") = strStuId
> Rst("studentName") = strStuName
> Rst("stdStatus") = "not logged in"
> Rst("C_subject") = strSltSbj
> If strExamSequence <> "" Then
> Rst("I_ExamSequence") = strExamSequence
> End If
> If strExamSeat <> "" Then
> Rst("I_ExamSeat") = strExamSeat
> End If
> If strManId <> "" Then
> Rst("C_ManId") = strManId
> End If
> Rst("L_TestID") = blnTestId
> Rst.Update
> Rst.Close
> Next
>
> set Rst=nothing
>
> If Err.number<>0 Then
> Conn.RollbackTrans
> Else
> Conn.CommitTrans
> End If
> 'definition of function fnCheckError :
> Function fnCheckError(strStatus)
> If Err.number=0 Then
> Exit Function
> Else
> showServerMessage("[" & strStatus & "]error:" & Err.Description)
> End If
> End Function
>
> 'display error message
> Function showServerMessage(strMsg)
> On Error Resume Next
> Dim strScrString
> strMsg = Replace(strMsg,"""","'")
> strMsg = Replace(strMsg,"\","\\")
> strMsg = Replace(strMsg,vbCrLf,"\n")
> strScrString = "<Script language=javascript>" & vbCrLf
> strScrString = strScrString & "var strMsg=" & Chr(34) & strMsg &
> Chr(34) & ";" & vbCrLf
> strScrString = strScrString & "strMsg=strMsg.replace(/\|/g,'\n');" &
> vbCrLf
> strScrString = strScrString & "alert(strMsg);" & vbCrLf
> strScrString = strScrString & "parent.window.close();" & vbCrLf
> strScrString = strScrString & "</script>" & vbCrLf
> Response.Write strScrString
> Response.End
> End Function
> I used ACCESS as a backend.



Relevant Pages