Re: ADODB.Recordset: Operation is not allowed when the object is closed. (3704)
- From: "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 17 Jul 2007 16:35:13 -0500
Randy Snyder wrote:
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<------------------
You open the recordset object twice, once when you invoke the Execute method
of the connection object, then again when you invoke the Open method of the
recordset object. I believe that accounts for the error message. Try:
Set rs = CreateObject("ADODB.RecordSet")
rs.ActiveConnection = cn
rs.Source = sqlText
rs.Open
--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--
.
- References:
- ADODB.Recordset: Operation is not allowed when the object is closed. (3704)
- From: Randy Snyder
- ADODB.Recordset: Operation is not allowed when the object is closed. (3704)
- Prev by Date: ADODB.Recordset: Operation is not allowed when the object is closed. (3704)
- Next by Date: pls pls pls help me out!!!!!!!!! Append new field in the existing table using ADO.
- Previous by thread: ADODB.Recordset: Operation is not allowed when the object is closed. (3704)
- Next by thread: pls pls pls help me out!!!!!!!!! Append new field in the existing table using ADO.
- Index(es):
Relevant Pages
|
|