Re: Handling Error in ADO



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 a
connection
to a DB in Vb 6.0. What will be the best way to handle the errors? Should
I
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? My
main problem is that I don't know how to test a recordset object to see if
it
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



.



Relevant Pages

  • Re: ADO Properties
    ... ADO.NET has same objects like Connection, Command object as ADO does. ... there is Dataset in place of Recordset. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: ADO control and SQL Session
    ... I defined my ADO in code Dimc xConnection As New ADODB.Connection ... I drag and drop the ADO control to a user form. ... I close the ADO record set connection ... The ADODC control exposes a .recordset property that is a reference to the ...
    (microsoft.public.vb.controls)
  • Re: adodb
    ... without knowing how the database is implemented. ... required to access a database when using ADO, although one can use ADO to ... A Connection object represents a unique session with a data source. ... A Recordset object represents the entire set of records from a base table ...
    (microsoft.public.vb.database.ado)
  • Re: adodb
    ... > without knowing how the database is implemented. ... > required to access a database when using ADO, although one can use ADO to ... > A Connection object represents a unique session with a data source. ... At any time, the Recordset object ...
    (microsoft.public.vb.database.ado)
  • Re: Need example of using ADO DataControl and DataGrid control - V
    ... > MSDN is where I learnt ADO. ... > ' Create connection string to access the database ... > ' Bind the recordset to the data grid. ... > Private Sub Command1_Click ...
    (microsoft.public.vb.database.ado)