View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
DBAL DBAL is offline
external usenet poster
 
Posts: 6
Default Recordset or Object is closed HELP PLEASE!

Guys,
I am getting this stubborn error anytime I try to do
anything with my recordset: '3704' Operation is not
allowed when the object is closed.

I don't understand why this recordset is closed no matter
how I write the code for the recordset. I've tried
the 'open method', the 'connection object' method, and
now the 'command object' method (if the recordset is the
object the error is referencing).

I have added SET NOCOUNT ON, and SET ANSI_WARNINGS OFF to
the SQL that is passed under the variable strSQL1. But
it doesn't help. PLEASE HELP ME CRACK THIS ONE!!!!

Here is my code: (there is some debugging code near the
bottom):

'Create the connection string and the Recordset
Set adoCn = New ADODB.Connection
With adoCn
.ConnectionString = "Provider=SQLOLEDB;Integrated
Security=SSPI;Trusted_Connection=yes;Persist Security
Info=False;Server=SQLSERVER;Database=m2mdata01;Uid =sa;
Pwd=;"
.CursorLocation = adUseServer
.Open
End With

Set adoCm = New ADODB.Command
With adoCm
Set .ActiveConnection = adoCn
.CommandType = adCmdText
.CommandText = strSQL1
.Execute
End With

Set adoRs = New ADODB.Recordset
With adoRs
Set .ActiveConnection = adoCn
.LockType = adLockReadOnly
.CursorLocation = adUseServer
.CursorType = adOpenStatic
.Open adoCm '"SET NOCOUNT ON SET ANSI_WARNINGS OFF"
End With


'Attemps to debug below.
MsgBox "Connection state is " & adoCn.State

MsgBox "Recordset state is " & adoRs.State

adoRs.NextRecordset

MsgBox adoRs.State

adoRs.NextRecordset

MsgBox adoRs.State

Do While adoRs.State < adStateOpen
Set adoRs = adoRs.NextRecordset
lTryCount = lTryCount + 1
If lTryCount 100 Then
Exit Do
End If
Loop
MsgBox lTryCount

If adoRs.BOF And adoRs.EOF Then
MsgBox "No records in this recordset!"
End If