Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Object was open Error -2147217915

1,292 views
Skip to first unread message

Adam Cain

unread,
Dec 31, 2002, 12:22:09 PM12/31/02
to
Doing this line of code I get the error message
"Object was open."

rs.Open Source, Conn, adOpenForwardOnly, adLockReadOnly

Source is a text string and I can copy it into query
analyzer and it runs just fine. I'm using VB6, SQL Server
2000, and ADO 2.6

any suggestions on what to try o rwhat to look at...
Thanks,
Adam

Val Mazur

unread,
Dec 31, 2002, 2:41:57 PM12/31/02
to
Adam,

Check if your recordset is not opened already. First you need to close it,
before opening it again.

--
Val Mazur
Microsoft MVP

"Adam Cain" <ac...@smc3.com> wrote in message
news:051901c2b0f1$26675bb0$cef82ecf@TK2MSFTNGXA08...

Howard Pinsley

unread,
Dec 31, 2002, 3:06:46 PM12/31/02
to
How did you create the rs (recordset) object reference?

"Adam Cain" <ac...@smc3.com> wrote in message
news:051901c2b0f1$26675bb0$cef82ecf@TK2MSFTNGXA08...

Adam Cain

unread,
Jan 2, 2003, 7:30:03 AM1/2/03
to
Here's the entire procedure I am using...

Public Function LoadRecordset(ByVal Source As String,
Optional ByVal ReadOnly As Boolean = True, Optional ByVal
Track As Boolean) As ADODB.Recordset
Dim rs As New ADODB.Recordset
Dim Conn As New ADODB.Connection
'Set Conn = New ADODB.Connection
Conn.ConnectionTimeout = MAX_CONN_WAIT
Conn.CommandTimeout = MAX_CMD_WAIT
Conn.CursorLocation = adUseClient
Conn.Open CONNECTION_STRING

Set rs.ActiveConnection = Conn
If ReadOnly Then


rs.Open Source, Conn, adOpenForwardOnly,
adLockReadOnly

Else
rs.Open Source, Conn, adOpenKeyset,
adLockOptimistic
End If
Set LoadRecordset = rs

'* SQL analysis
If RunningInIDE And Track Then frmSQL.AddCommand Source
End Function

Then I am calling it from another procdure like this...

Dim rsAgg As ADODB.Recordset
'sql assigned in this chunk as inidicated
Set rsAgg = LoadRecordset(sql, True, True)

In each case the variable is declared within the procedure
and is not used anywhere else.

>.
>

Ramesh

unread,
Jan 2, 2003, 9:28:09 AM1/2/03
to
The error message seems to indicate that the recordset object is in an
invalid state. How many records are you trying to return? What happens if
you try to return less number of records?
Also can you try the following line to open your recordset.
set rs = conn.execute(source)

This will return a forwardonly readonly recordset too.

Hope this helps.

Please check this and see.
Ramesh Thyagarajan, MCSD,MCDBA
Microsoft Developer support

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? For information about the Microsoft Strategic Technology
Protection Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/security.

Adam Cain

unread,
Jan 3, 2003, 8:33:02 AM1/3/03
to
Asking about record count pointed me in the right
direction. My SQl statement didn't have some joins
properly defined so I was returning over 1.5 million
records when I should have been returning about 3500. Once
I corrected that I was able to run it just fine.

FYI, I also discovered that it was actually returning as
much of the recordset as my memory could hold but it
didn't seem to send the proper ending of the recordset and
that was what cauesd the error.

Anyway, the problems fixed so thanks for the help.

0 new messages