Re: Handling Error in ADO
- From: HLong <HLong@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 20 Feb 2007 06:01:08 -0800
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? Could you please help me to understand this? TIA
"Stephen Howe" wrote:
.
"HLong" <HLong@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:A9520100-8EBC-450A-A9F1-F8BE3C49FA19@xxxxxxxxxxxxxxxx
I would like to know the best way to handle errors when creating aconnection
to a DB in Vb 6.0. What will be the best way to handle the errors? ShouldI
set both the connection and recordsets objects to "Nothing", if an error
ocurrs?
No. The errors collection is part of the Connection object, you might want
to examine that to see what type of errors are occuring. These will be ADO
errors. Generally Provider-specific errors show up as COM errors
Shoud I try to close them first, and then set them to nothing? Myit
main problem is that I don't know how to test a recordset object to see if
is open, before trying to close it.
You should examine the Recordset State property and see if the Open bit is
set
Something like (pseudo-code, untested)
IF rs <> Nothing THEN
IF ((rs.State AND adStateOpen) <> 0) THEN
rs.Close
END IF
rs = Nothing
END IF
IF conn <> Nothing THEN
IF ((conn.State AND adStateOpen) <> 0) THEN
conn.Close
END IF
conn = Nothing
END IF
Does it matter if they are open when I
set them to "Nothing"?
That is a good question which I dont know the answer to.
Certainly nothing can go wrong with the object itself, but the resources it
mananges is something else...
I never heard anything definitive on this.
I mean what happens if an active recordset, connection & command object go
out of scope?
And what happens if in a pending transaction (I assume that any pending
transactions are aborted)?
Generally I think the database recovers
But I always tend to close cleanly and have not seen any _guaranteed_ ADO
answers on this or what the providers do in such circumstancess
Stephen Howe
- Follow-Ups:
- Re: Handling Error in ADO
- From: Stephen Howe
- Re: Handling Error in ADO
- References:
- Re: Handling Error in ADO
- From: Stephen Howe
- Re: Handling Error in ADO
- Prev by Date: Re: Handling Error in ADO
- 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
|
|