By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,900 Members | 1,329 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,900 IT Pros & Developers. It's quick & easy.

sqlcommand.dispose???

P: n/a
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.
Jun 12 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Jun 12, 10:34 am, cj <c...@nospam.nospamwrote:
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

Jun 12 '07 #2

P: n/a
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

"cj" <cj@nospam.nospamschreef in bericht
news:OO**************@TK2MSFTNGP06.phx.gbl...
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.

Jun 12 '07 #3

P: n/a

"cj" <cj@nospam.nospamwrote in message
news:OO**************@TK2MSFTNGP06.phx.gbl...
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.
ADO.Net Using statement.

http://pluralsight.com/blogs/fritz/a...4/28/7834.aspx

Jun 12 '07 #4

P: n/a
"Mr. Arnold" <MR. Ar****@Arnold.comschrieb:
>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.

ADO.Net Using statement.

http://pluralsight.com/blogs/fritz/a...4/28/7834.aspx
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
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jun 12 '07 #5

P: n/a
On Jun 12, 4:24 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h...@gmx.atwrote:
"Mr. Arnold" <MR. Arn...@Arnold.comschrieb:
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.
ADO.Net Using statement.
http://pluralsight.com/blogs/fritz/a...4/28/7834.aspx

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
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Hmm, never knew you could do that - thanks Herfried!
Thanks,

Seth Rowe

Jun 12 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.