Call Dispose on OleDbCommand?

  • Thread starter Thread starter JohnMSyrasoft
  • Start date Start date
J

JohnMSyrasoft

1. Should you explicitly call Dispose on OleDb objects like OleDbCommand or
OleDbConnection?

2. In VB.NET for the keyword USING (as in "Using cn As New
OleDbConnection(...)...")

Should you explicitly call the Close method on the OleDbConnection object or
will the object be closed and disposed automatically once the Using block is
exited?

Thanks for your insights.
 
You should dispose of any object that implements the IDisposable interface.
Using "Using" will accomplish that automically.
Calling Dispose will close the connection if it is not already closed, but
you should still call "close" as soon as you can because there may be a
delay between when you are ready for the connection to be closed and when
the code reaches the Dispose (or end of Using) command.

-Scott
 
1. Should you explicitly call Dispose on OleDb objects like OleDbCommand
or
OleDbConnection?


Both are managed resources (the Connection needs a close at the moment that
it is not opened by the dataadapter automaticly)
2. In VB.NET for the keyword USING (as in "Using cn As New
OleDbConnection(...)...")

The "using" inside a method is a short way of using resources. It implements
a dispose automaticly (in the connection the dispose implements a close).

Cor
 
Back
Top