Two questions... one easy, one hard

Two questions... one easy, one hard

Post by Dan Billingsle » Thu, 10 Feb 2000 04:00:00



Well, at least I think it will turn out that way... :)

1)  What does a .recordcount of -1 mean on an ADO recordset?  I've seen that
sometimes I get this and sometimes I get the real value, but the causing
factor isn't obvious to me.

2) Does anyone know why I would get the following message trying to perform
a .close on a recordset?

    3219:  The operation requested by the application is not allowed in this
context.

If the query does not find any records, I can close the recordset without
any problems, but if it does include a record, I do get the error.  (BTW, in
both cases the recordcount is reported as -1).

There is absolutely no info in the VB help or knowledge base that I can
find.

 
 
 

Two questions... one easy, one hard

Post by Adrian Forbe » Thu, 10 Feb 2000 04:00:00


Quote:> 1)  What does a .recordcount of -1 mean on an ADO recordset?

http://www.aspfaq.com/faq/faqShow.asp?fid=24

Quote:> 2) Does anyone know why I would get the following message trying to
perform
> a .close on a recordset?

Post more of the code

 
 
 

Two questions... one easy, one hard

Post by Ghislain Tangua » Thu, 10 Feb 2000 04:00:00




Quote:> Well, at least I think it will turn out that way... :)

> 1)  What does a .recordcount of -1 mean on an ADO recordset?  I've seen
that
> sometimes I get this and sometimes I get the real value, but the causing
> factor isn't obvious to me.

    You have to be in static cursortype to use this property
    rs.Open strSQL, ProspectData.ConnectionString, adOpenStatic

Quote:

> 2) Does anyone know why I would get the following message trying to
perform
> a .close on a recordset?

>     3219:  The operation requested by the application is not allowed in
this
> context.

    Do you use an On Error Goto ErrHandler. If yes delete it and replace it
by On Error resume Next
    If not insert at the beginning of your sub On error resume next, so if
ther's any error when you try
     to update your database the treatment will continue and the recordset
will be close.

Quote:

> If the query does not find any records, I can close the recordset without
> any problems, but if it does include a record, I do get the error.  (BTW,
in
> both cases the recordcount is reported as -1).

> There is absolutely no info in the VB help or knowledge base that I can
> find.

 
 
 

Two questions... one easy, one hard

Post by Ghislain Tangua » Thu, 10 Feb 2000 04:00:00




Quote:> Well, at least I think it will turn out that way... :)

> 1)  What does a .recordcount of -1 mean on an ADO recordset?  I've seen
that
> sometimes I get this and sometimes I get the real value, but the causing
> factor isn't obvious to me.

> 2) Does anyone know why I would get the following message trying to
perform
> a .close on a recordset?

    Use a static cursor
    rs.Open strSQL, ProspectData.ConnectionString, adOpenStatic

Quote:>     3219:  The operation requested by the application is not allowed in
this
> context.

> If the query does not find any records, I can close the recordset without
> any problems, but if it does include a record, I do get the error.  (BTW,
in
> both cases the recordcount is reported as -1).

    use On Error Resume Next. Don't use On Error Goto with an open recordset
Quote:

> There is absolutely no info in the VB help or knowledge base that I can
> find.

 
 
 

Two questions... one easy, one hard

Post by Dan Billingsle » Thu, 10 Feb 2000 04:00:00


Wow, thanks for the quick responses.

Quote:> > 1)  What does a .recordcount of -1 mean on an ADO recordset?  I've seen
> that
> > sometimes I get this and sometimes I get the real value, but the causing
> > factor isn't obvious to me.

>     You have to be in static cursortype to use this property
>     rs.Open strSQL, ProspectData.ConnectionString, adOpenStatic

Yes, that was indeed it.  What was confusing me is that the cursor type has
to be static, and only static.  I was under the impression from other
information, like the link in the first response to my post, that it just
couldn't be forward-only.  I was using Dynamic.

Quote:

> > 2) Does anyone know why I would get the following message trying to
> perform
> > a .close on a recordset?

> >     3219:  The operation requested by the application is not allowed in
> this
> > context.

This problem was happening in my error handler.  (BTW, "on error resume
next" was already set, but this error still got raised.  Interesting, eh?)
I heard at a Microsoft MSDN cafe recently that setting a recordset object to
nothing without closing it first causes a memory leak, so I was trying to
close it.  But you can't close a recordset when the current record has been
changed.  In my case I had tried to insert a duplicate key, so the current
record was a new one that hadn't been updated.

I solved the problem by adding an additional check to my cleanup routine:

Public Sub KillRecordset(ByRef rsRecordset As ADODB.Recordset)

  If Not (rsRecordset Is Nothing) Then
    If rsRecordset.State = adStateOpen Then
      If rsRecordset.EditMode <> adEditNone Then
        rsRecordset.CancelUpdate
      End If
      rsRecordset.Close
    End If
    Set rsRecordset = Nothing
  End If

End Sub

I guess this was one of those duh! ones that should have been obvious to me.
:)

 
 
 

Two questions... one easy, one hard

Post by Paul » Thu, 10 Feb 2000 04:00:00


Why would you not use an error handler to check for known, correctable
errors, then resume code execution?  In my experience, using On Error Resume
Next leads to bugs that are very difficult to find....Don't get me wrong, I
use On Error Resume Next, especially in _Resize event handlers and other
"non-critical" portions of code, but to me, if a recordset error is
encountered, I'd like to know about it and have a opportunity to fix it.

....

Quote:>     use On Error Resume Next. Don't use On Error Goto with an open

recordset
...
 
 
 

Two questions... one easy, one hard

Post by Dan Billingsle » Fri, 11 Feb 2000 04:00:00


No argument here.  But, in the end, at some point you're going to have to
"bail out", and I wrote the KillRecordset routine to ensure that any
recordset in any potential state would be closed before being deallocated,
to prevent memory leaks.

I never use on error resume next except in the error handler.  As I
understand it, the idea there is to prevent the real error from being masked
because another error is raised by some action in the error handler itself,
like closing a recordset or writing to an error log file.  This would be
after doing the kind of error recovery you're talking about, I think.

Frankly, the "resume next" is something that was suggested at one of the
MSDN cafes, and, like many things Microsoft suggests, I'm not sure yet how
much I agree with it, for reasons you stated.


Quote:> Why would you not use an error handler to check for known, correctable
> errors, then resume code execution?  In my experience, using On Error
Resume
> Next leads to bugs that are very difficult to find....Don't get me wrong,
I
> use On Error Resume Next, especially in _Resize event handlers and other
> "non-critical" portions of code, but to me, if a recordset error is
> encountered, I'd like to know about it and have a opportunity to fix it.