Call Dispose on OleDbCommand?

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.
 
S

Scott M.

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
 
C

Cor Ligthert[MVP]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top