J
Jason
I read there is no difference between calling Close vs. Dispose on
Connection objects.
Is this true?
Connection objects.
Is this true?
Dispose closes the connection and discards the object. It has no further
effect. It does not impact the connection pool.
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
"Chris Lyon [MSFT]" said:Bill,
Dispose does not "discard the object".
See http://weblogs.asp.net/clyon/archive/2004/09/21/232445.aspx
Close() and Dispose() should be equivalent. See
http://msdn.microsoft.com/library/d.../en-us/cpgenref/html/cpconfinalizedispose.asp
for more information.
-Chris
--------------------
Dispose closes the connection and discards the object. It has no further
effect. It does not impact the connection pool.
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no
rights.
__________________________________
--
This posting is provided "AS IS" with no warranties, and confers no
rights. Use of included script samples are subject to the terms specified
at
http://www.microsoft.com/info/cpyright.htm
Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.
Okay, let me rephrase. Once you call Dispose, you can't use the object's
properties or methods. The object remains in memory until the GC flushes its
memory... but it's "discarded" as far as your code is concerned. Close
simply marks the connection as reusable (in the pool) and you can
subsequently inspect Connection properties and use the Open method again.
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
"Chris Lyon [MSFT]" said:Bill,
Dispose does not "discard the object".
See http://weblogs.asp.net/clyon/archive/2004/09/21/232445.aspx
Close() and Dispose() should be equivalent. See
http://msdn.microsoft.com/library/d.../en-us/cpgenref/html/cpconfinalizedispose.asp
for more information.
-Chris
--------------------
Dispose closes the connection and discards the object. It has no further
effect. It does not impact the connection pool.
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no
rights.
__________________________________
I read there is no difference between calling Close vs. Dispose on
Connection objects.
Is this true?
--
This posting is provided "AS IS" with no warranties, and confers no
rights. Use of included script samples are subject to the terms specified
at
http://www.microsoft.com/info/cpyright.htm
Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.
properties and methods. See this blog post, in particular the comments:"Chris Lyon [MSFT]" said:Bill,
Calling Dispose() doesn't then prohibit you from calling the object's
correctly, then Close and Dispose are equivalent.http://weblogs.asp.net/clyon/archive/2004/09/23/233464.aspx
If the class' developer followed the Dispose Pattern (link below)
calling Close or Dispose. The same InvalidOperationExceptions will beFor example, a SQLConnection object will have the same behaviour after
rights. Use of included script samples are subject to the terms specified at(like ChangeDatabase()) are called, but not all.
-Chris
--------------------
Okay, let me rephrase. Once you call Dispose, you can't use the object's
properties or methods. The object remains in memory until the GC flushes its
memory... but it's "discarded" as far as your code is concerned. Close
simply marks the connection as reusable (in the pool) and you can
subsequently inspect Connection properties and use the Open method again.
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
"Chris Lyon [MSFT]" said:Bill,
Dispose does not "discard the object".
See http://weblogs.asp.net/clyon/archive/2004/09/21/232445.aspx
Close() and Dispose() should be equivalent. See
http://msdn.microsoft.com/library/d.../en-us/cpgenref/html/cpconfinalizedispose.asp
for more information.
-Chris
--------------------
Dispose closes the connection and discards the object. It has no further
effect. It does not impact the connection pool.
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no
rights.
__________________________________
I read there is no difference between calling Close vs. Dispose on
Connection objects.
Is this true?
--
This posting is provided "AS IS" with no warranties, and confers no
rights. Use of included script samples are subject to the terms specified
at
http://www.microsoft.com/info/cpyright.htm
Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.
message are best directed to the newsgroup/thread from which theyhttp://www.microsoft.com/info/cpyright.htm
Note: For the benefit of the community-at-large, all responses to this
"Chris Lyon [MSFT]" said:Bill,
Calling Dispose() doesn't then prohibit you from calling the object's
properties and methods. See this blog post, in particular the comments:
http://weblogs.asp.net/clyon/archive/2004/09/23/233464.aspx
If the class' developer followed the Dispose Pattern (link below)
correctly, then Close and Dispose are equivalent.
For example, a SQLConnection object will have the same behaviour after
calling Close or Dispose. The same InvalidOperationExceptions will be
thrown when some methods
(like ChangeDatabase()) are called, but not all.
-Chris
--------------------
Okay, let me rephrase. Once you call Dispose, you can't use the object's
properties or methods. The object remains in memory until the GC flushes
its
memory... but it's "discarded" as far as your code is concerned. Close
simply marks the connection as reusable (in the pool) and you can
subsequently inspect Connection properties and use the Open method again.
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no
rights.
__________________________________
"Chris Lyon [MSFT]" said:Bill,
Dispose does not "discard the object".
See http://weblogs.asp.net/clyon/archive/2004/09/21/232445.aspx
Close() and Dispose() should be equivalent. See
http://msdn.microsoft.com/library/d.../en-us/cpgenref/html/cpconfinalizedispose.asp
for more information.
-Chris
--------------------
Dispose closes the connection and discards the object. It has no further
effect. It does not impact the connection pool.
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no
rights.
__________________________________
I read there is no difference between calling Close vs. Dispose on
Connection objects.
Is this true?
--
This posting is provided "AS IS" with no warranties, and confers no
rights. Use of included script samples are subject to the terms
specified
at
http://www.microsoft.com/info/cpyright.htm
Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.
--
This posting is provided "AS IS" with no warranties, and confers no
rights. Use of included script samples are subject to the terms specified
at
http://www.microsoft.com/info/cpyright.htm
Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.
Chris,
Here is reflected code out of SqlConnection.Dispose ---
protected override void Dispose(bool disposing)
{
switch (this._objectState)
{
case ConnectionState.Open:
{
goto Label_0017;
}
}
goto Label_0035;
Label_0017:
if (disposing)
{
this.Close();
this._connectionOptions = null;
this._cachedOptions = null;
this._connectionString = null;
}
Label_0035:
base.Dispose(disposing);
}
You can clearly see Dispose does more than Close, it sets certain properties
to null. .. therefore Dispose is not the same as Close.
I think Bill's right dude :-/
- Sahil Malik
You can reach me thru my blog at
http://www.dotnetjunkies.com/weblog/sahilmalik
properties and methods. See this blog post, in particular the comments:"Chris Lyon [MSFT]" said:Bill,
Calling Dispose() doesn't then prohibit you from calling the object'scorrectly, then Close and Dispose are equivalent.http://weblogs.asp.net/clyon/archive/2004/09/23/233464.aspx
If the class' developer followed the Dispose Pattern (link below)calling Close or Dispose. The same InvalidOperationExceptions will beFor example, a SQLConnection object will have the same behaviour after
thrown when some methodsrights. Use of included script samples are subject to the terms specified at(like ChangeDatabase()) are called, but not all.
-Chrismessage are best directed to the newsgroup/thread from which theyhttp://www.microsoft.com/info/cpyright.htm
Note: For the benefit of the community-at-large, all responses to this
originated.
like in this case a little more cleanup is happening. I'm not familiar"Chris Lyon [MSFT]" said:Hm. Interesting.
According to the Dispose Pattern, Close should call Dispose. It looks
appropriate to continue to use a SQLConnection object after it's beenwhat kind of effects this might have on your object, or whether it's
a connection object, calling either Close or Dispose is sufficient to freeClose and Dispose are equivalent, in the sense that when you're done with
rights. Use of included script samples are subject to the terms specified at-Chris
--------------------
Chris,
Here is reflected code out of SqlConnection.Dispose ---
protected override void Dispose(bool disposing)
{
switch (this._objectState)
{
case ConnectionState.Open:
{
goto Label_0017;
}
}
goto Label_0035;
Label_0017:
if (disposing)
{
this.Close();
this._connectionOptions = null;
this._cachedOptions = null;
this._connectionString = null;
}
Label_0035:
base.Dispose(disposing);
}
You can clearly see Dispose does more than Close, it sets certain properties
to null. .. therefore Dispose is not the same as Close.
I think Bill's right dude :-/
- Sahil Malik
You can reach me thru my blog at
http://www.dotnetjunkies.com/weblog/sahilmalik
properties and methods. See this blog post, in particular the comments:"Chris Lyon [MSFT]" said:Bill,
Calling Dispose() doesn't then prohibit you from calling the object'scorrectly, then Close and Dispose are equivalent.http://weblogs.asp.net/clyon/archive/2004/09/23/233464.aspx
If the class' developer followed the Dispose Pattern (link below)calling Close or Dispose. The same InvalidOperationExceptions will beFor example, a SQLConnection object will have the same behaviour after
thrown when some methodsflushes(like ChangeDatabase()) are called, but not all.
-Chris
--------------------
Okay, let me rephrase. Once you call Dispose, you can't use the object's
properties or methods. The object remains in memory until the GC
itshttp://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/h tml/cpconfinalizedispose.aspmemory... but it's "discarded" as far as your code is concerned. Close
simply marks the connection as reusable (in the pool) and you can
subsequently inspect Connection properties and use the Open method again.
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Bill,
Dispose does not "discard the object".
See http://weblogs.asp.net/clyon/archive/2004/09/21/232445.aspx
Close() and Dispose() should be equivalent. Seerights. Use of included script samples are subject to the terms specified atfor more information.
-Chris
--------------------
Dispose closes the connection and discards the object. It has no further
effect. It does not impact the connection pool.
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no
rights.
__________________________________
I read there is no difference between calling Close vs. Dispose on
Connection objects.
Is this true?
--
This posting is provided "AS IS" with no warranties, and confers no
rights. Use of included script samples are subject to the terms specified
at
http://www.microsoft.com/info/cpyright.htm
Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.message are best directed to the newsgroup/thread from which theyhttp://www.microsoft.com/info/cpyright.htm
Note: For the benefit of the community-at-large, all responses to this
originated.
message are best directed to the newsgroup/thread from which theyhttp://www.microsoft.com/info/cpyright.htm
Note: For the benefit of the community-at-large, all responses to this