ADODB.Recordset: Operation is not allowed when the object is closed. (3704)



I have very little experience with ADO. I wrote the script below. I am attempting to open a connection to a Microsoft SQL database, run a query and then echo out the data that is returned.

I am able to establish a connection with the database; however, I get a "ADODB.Recordset:Operation is not allowed when the object is closed." (Error Number 3704)

What I am missing? I appreciate any assistance you can provide.

-Randy

------------8<------------------

sqlText = "USE IMYahooDB " & _
"select * " & _
"from messages " & _
"where (sender_im ='sip:joe_user@xxxxxxxxx') or " &_
"(recipient_im = 'sip:joe_user@xxxxxxxxx') " & _
"order by message_date"

Set cn = CreateObject("ADODB.Connection")

cn.Open = "PROVIDER=sqloledb;" &_
"DATA SOURCE=DBServer01;" &_
"DATABASE=IMYahooDB;" &_
"Integrated Security=SSPI"

If cn.State = 1 Then
WScript.Echo "Connection is open."
Else
WScript.Echo "There is a problem with the connection."
WScript.Quit(1)
End If

'Set rs = CreateObject("ADODB.RecordSet")
Set rs = cn.Execute(sqlText)
rs.ActiveConnection = cn
rs.Open sqlText,cn

If rs.EOF Then
WScript.Echo "No records returned."
Else
Do While NOT rs.EOF
WScript.Echo rs("sender_name")
WScript.Echo rs("message_date")
rs.MoveNext
Loop
End If

cn.Close
rs.Close
Set cn = Nothing
Set rs = Nothing
WScript.Quit(0)

------------8<------------------
.



Relevant Pages

  • ADO Object in VB Script Only Calls SQLGetData for column 1
    ... I try I can only get the script to retrieve the first column of my query. ... Dim adoConnection As ADODB.Connection ... '—Build our connection string to use when we open the connection -- ...
    (microsoft.public.data.ado)
  • Re: Efficiency of mysql_close()
    ... I am working on a script for PHP that handles mysql_connections. ... Right now, each time I query the database, i open the connection using ... mysql_connect, and after I get my resource result, I use ...
    (comp.lang.php)
  • RE: Perl DBI->Connect: how to detect a a lost connection
    ... followed by a while loop which runs a query for this connection at 60 ... I suggest you connect to the database every time around the loop instead ... connection will be verified and used again if it is still valid. ...
    (perl.beginners)
  • Re: I dont close my databases
    ... >>links are automatically closed at the end of the script's execution. ... > you don't need the database connection past a certain point in the page. ... if you do lots of processing after the query you should close ... But it isn't wise to close connection after each query in same script ...
    (alt.php)
  • Re: ADODB.Recordset: Operation is not allowed when the object is closed. (3704)
    ... attempting to open a connection to a Microsoft SQL database, ... You open the recordset object twice, once when you invoke the Execute method ...
    (microsoft.public.data.ado)