Groups | Blog | Home
all groups > dotnet ado.net > april 2008 >

dotnet ado.net : Call Dispose on OleDbCommand?



JohnMSyrasoft
4/7/2008 12:49:02 PM
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?

Scott M.
4/7/2008 5:25:01 PM
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

[quoted text, click to view]

Cor Ligthert[MVP]
4/8/2008 6:12:40 AM
[quoted text, click to view]


Both are managed resources (the Connection needs a close at the moment that
it is not opened by the dataadapter automaticly)

[quoted text, click to view]

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
AddThis Social Bookmark Button