473,394 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

sqlcommand.dispose???

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
5 2696
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
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

"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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Henrik Dahl | last post by:
Hello! After I've finished using an instance of the SqlCommand class, should I then invoke Dispose() on the instance. I suppose so, as there is a Dispose method, but what does it actually...
1
by: Soren Jorgensen | last post by:
Hi, When executing following statement "select distinct Name from CustomerParameters for xml auto" - XmlReader reads "<customerparameters name="Www.Mail.Generel" />" - but SQL Query Manager...
15
by: Khurram | last post by:
I have a problem while inserting time value in the datetime Field. I want to Insert only time value in this format (08:15:39) into the SQL Date time Field. I tried to many ways, I can extract...
3
by: Jason Huang | last post by:
Hi, In C#.Net, can we have more than one SqlCommand in a SqlConnection? And in one SqlCommand, can we have more than one SqlDataReader in a SqlCommand? In what situation should I use...
0
by: Agnes | last post by:
I got a silly question about Sqlcommand . In my form, there are 5 methods which use the same sqlcommand to execute reader. I had create and dispose for each sqlcommand in every method. Some said...
1
by: Agnes | last post by:
Silly question again. I found that Even I run Sqlcommand.dispose, I still can use it , does anyone know ?
2
by: fniles | last post by:
I am using .Net 2003 and querying a SQL Server 2000 database. I read the database in a loop, but on every iteration I set the SQLCommand to new, set it, execute it, dispose and set it to nothing....
4
by: =?Utf-8?B?Sm9uIEphY29icw==?= | last post by:
For MS SQL Server... I am used to declaring local variables in my SQL queries... Declare @MyInt int, @MyChar varchar(33) Parameters were idenfitied with a colon... Where ModDate :MyDate But,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.