sqlcommand.dispose???

  • Thread starter Thread starter cj
  • Start date Start date
C

cj

When I make a request of our sql server I Dim A New SqlConnection and I
Dim A New SqlCommand. The sqlcommand gets it's connection property set
to the sqlconnection. I've recently read the I need to dispose of the
sqlconnection after closing it. Shouldn't I then also dispose of the
sqlcommand???? Both have dispose methods.
 
When I make a request of our sql server I Dim A New SqlConnection and I
Dim A New SqlCommand. The sqlcommand gets it's connection property set
to the sqlconnection. I've recently read the I need to dispose of the
sqlconnection after closing it. Shouldn't I then also dispose of the
sqlcommand???? Both have dispose methods.

There's a few opinions on this - basically, calling dispose on the
objects in the System.Data namespace (except for the Connection
objects) doesn't do very much, so it isn't really necessary.
Personally, I wrap it in a Using block but it won't be an application
breaker if I don't.

Thanks,

Seth Rowe
 
cj,

The old C++ people want to dispose, (they want a deconstructor)
The old VB6 people want to set it to nothing (they have read that)

Because of that there are lot of tales on internet. One of them.
They did not make that method for nothing. Something if you have to use
forever all methods that exist in a class.

One of the reasons that there is managed code is to make the need of that
not direct neccesary anymore (not in all circumstances, by instance GDI uses
a lot of resources so there it is recomended because of to free the
resources).

You can use Dispose or Close. The Dispose is the same as the close with the
exception that it removes overloaded the actual connectionstring from the
object.

(The using has the dispose in it).

Cor
 
Well, it seems that the author of the above blog entry is missing this
feature of VB's 'Using' statement:

\\\
Using ResourceA, ResourceB, ResourceC
...
End Using
///

Hmm, never knew you could do that - thanks Herfried!


Thanks,

Seth Rowe
 
Back
Top