Re: Handling Error in ADO
- From: "Mark J. McGinty" <mmcginty@xxxxxxxxxxxxxxx>
- Date: Thu, 22 Feb 2007 08:55:06 -0800
"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.5on
and
the list of recordset properties the STATE property is not listed,on
however
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
.
- Follow-Ups:
- Re: Handling Error in ADO
- From: HLong
- Re: Handling Error in ADO
- References:
- Re: Handling Error in ADO
- From: Stephen Howe
- Re: Handling Error in ADO
- From: HLong
- Re: Handling Error in ADO
- From: Stephen Howe
- Re: Handling Error in ADO
- Prev by Date: Re: derived field problem
- Next by Date: Re: Handling Error in ADO
- Previous by thread: Re: Handling Error in ADO
- Next by thread: Re: Handling Error in ADO
- Index(es):
Relevant Pages
|
|