asp_databases thread: Re: Operation is not allowed when the object is...
A lot of people have been asking about this error. And recently I myself
was stumped by it unless by chance I discovered the solution was simply
to check the state of the recordset and also to ensure that you have SET
NOCOUNT ON in any stored procedure with possible multiple selects. Also
as far as I know, it happens with OLEDB and not ODBC.
Anyway the solution is to check the state of the recordset.
If Not RSmp3 Is Nothing Then
If Rsmp3.State = 'whatever the enum is for open
Do Until Rsmp3.EOF
Loop
...
End If
...
End If
http://www.activedataonline.com.au/
> Hi, I am getting this error "Operation is not allowed when the object
is
> closed." But if I only want to insert the data, I don't get any error.
> However if I query the information back out, the code gives me an
error.
> Please help. Thanks.
>
>
> Set objConn = Server.CreateObject("ADODB.Connection") 'creating
> active connection'
> objConn.Open "Provider= SQLOLEDB;Persist Security Info=False;" &
_
> "DSN=MP3DB;DATABASE=XXXDB;UID=sa;PWD=;"
>
> Set RSmp3 = Server.CreateObject("ADODB.Recordset")
> RSmp3.CursorLocation = adUseClient
> RSmp3.LockType = adLockReadOnly
> SQL = "INSERT INTO XXXX (A,B,C,D,E,F)" &_
> "VALUES('" & A & "','" & B & "','" & C & "','" & D & "','" &
E
> & "','" & F & "')"
>
> 'Response.Write(SQL)
>
> RSmp3.open SQL, objConn
>
> Response.Write ("<TABLE BORDER=0 CELLPADDING=0
> CELLSPACING=0><TR><TD>")
>
> RSmp3.MoveFirst '<---- This is where it gives me the error
> if not RSmp3.EOF Then
> while not RSmp3.EOF
> Response.Write RSmp3("LANGUAGES")
> Response.Write("</TD><TD>")
> RSmp3.MoveNext
> wend
> End if
> Response.Write("</TD></TR></TABLE>")
>
>
> 'RSmp3.close
> 'Set RSmp3 = nothing
> objConn.Close
> Set objConn = nothing