Re: Handling Error in ADO




"Stephen Howe" <stephenPOINThoweATtns-globalPOINTcom> wrote in message
news:ujIzYhQVHHA.1200@xxxxxxxxxxxxxxxxxxxxxxx
One more thing. I just noticed that the book I am using is for ADO 2.5
and
on
the list of recordset properties the STATE property is not listed,
however
on
my code I am referencing ADO 2.8 and it has a STATE property. Thank you
again. Now, on your test you use ((rs.State And adStateOpen) <> 0),
could
you explain why the double test (rs.State and adStateOpen). Is it to be
really sure that it is open before trying to close it? Wouldn't
(rs.State
<>
0) be enough?

No. Becasuse State records other bits that might be set, that technically
are othogonal to being open.

I think maybe what the OP missed is that in this case AND is a bitwise
operator, not a logical operator. (VB overloads the AND operator, in
C/C++/Javascript its & [bitwise] vs && [logical].) So the expression does
not test rs.State twice, it tests the result of rs.State [bitwise] AND
asStateOpen.

State could be one or bits set of

adStateClosed 0 Object is closed
adStateConnecting 2 Object is connecting
adStateExecuting 4 Object is executing
adStateFetching 8 Object is fetching
adStateOpen 1 Object is open

Mind you, if the RecordSet was Fetching or Executing or Connecting, could
you close it in the midst of these actions?
I am not sure. Some of these occur if you request asynchronous action.

Actually, unless you use the recordset asynchronously, you will never see
any state other than adStateOpen, because the recordset call will be
blocking until any of those other states have passed. Further, you will
only see adStateConnecting if you opt to pass a connection string instead of
an already opened connection (the latter, of course, being best practice.)

In practice, with synchronous code, rs.State > 0 is an adequate test.


I think if the State is Open you are in a postion to Close, with the
others
I have no idea.

Attempting to close a recordset while its executing or fetching causes an
error, you must call Cancel and wait until State = adStateOpen before
closing.


-Mark


Cheers

Stephen Howe




.



Relevant Pages

  • Re: Handling Error in ADO
    ... Thaks Mark for your explanation. ... Mind you, if the RecordSet was Fetching or Executing or Connecting, could ... only see adStateConnecting if you opt to pass a connection string instead of ... an already opened connection ...
    (microsoft.public.data.ado)
  • Re: How do I know if a RecordSet is open?
    ... hasn't been created with a Command object (but just via ... 'recordset is closed ... The State property is a bitmask so you should always mask the bit you're wanting to check. ... For example, in an asynchronous operation, the state could be a combination of adStateOpen and any of adStateConnecting, adStateExecuting, or adStateFetching. ...
    (microsoft.public.vb.general.discussion)
  • Re: How to determine if a connection is active
    ... (or search msdn for adodb api reference) ... > And I agree with you that I shouldn't needlessly leave the connection ...
    (microsoft.public.excel.programming)