![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| ||||
| ||||
|
|
What are their differences? |
|
Q1: Should we call both Close() and Dispose() on an object in finally block? |
|
If not, then which one should we call and why? |
|
Q2: If it makes sense to call both, does the order of calling them matter? |
#3
| |||
| |||
|
|
"gnewsgroup" <gnewsgr... (AT) gmail (DOT) com> wrote in message news:30d32f99-aed8-4bcb-a585-405b4e86ad4d (AT) s8g2000prg (DOT) googlegroups.com... What are their differences? Close() closes the connection and returns it to the pool, leaving the object in memory until the garbage collector decides it can destroy it - Dispose() removes it from memory by first calling Close:http://blog.devstone.com/aaron/archi...06/03/184.aspx |
|
Q1: Should we call both Close() and Dispose() on an object in finally block? No. If not, then which one should we call and why? Neither - use the "using (.......) {.....}" syntax as described in the above article. |
#4
| |||
| |||
|
|
"gnewsgroup" <gnewsgroup (AT) gmail (DOT) com> wrote in message Neither - use the "using (.......) {.....}" syntax as described in the above article. |
|
Think outside the box! ************************************************* |
#5
| |||
| |||
|
|
Thank you. So, I guess if the connection object is gonna be used soon, we better simply call Close() to improve the performance. |
|
I am aware of the using syntax, but have never seriously used it. |
|
I read the article which you referred to above. Very nice, but I am sorta confused by this: quote When Close() is called (or Dispose() by virtue of what it does) the connection is not actually closed but is returned to the database connection pool - remember that the connection pool is a collection of SQL Connections, not SqlConnection objects. /quote Does the author imply (by way of the parenthesized part) that Close() and Dispose makes no difference in terms of returning the connection object to the conection pool? |
#6
| |||
| |||
|
|
This is a bit misleading, as the following are functionally equivalent: |
|
The main advantage of using, here, is it is more succinct and therefore faster to code. |
#7
| ||||
| ||||
|
|
You know, a SqlConnection object, a SqlCommand object, a SqlDataReader object and many other data access objects, have a Close() method and a Dispose() method. What are their differences? Q1: Should we call both Close() and Dispose() on an object in finally block? If not, then which one should we call and why? |
|
Q2: If it makes sense to call both, does the order of calling them matter? |
|
Q3: Does the order of calling either Close() or Dispose() or both matter on a SqlConnection object, a SqlCommand object which contains this connection, a SqlDataReader object which is a result of ExecuteReader of this SqlCommand object? |
|
Think outside the box! ************************************************* |
#8
| |||
| |||
|
|
"Cowboy (Gregory A. Beamer)" <NoSpamMgbworld (AT) comcast (DOT) netNoSpamM> wrote in message news:uvP4vVZQIHA.5524 (AT) TK2MSFTNGP05 (DOT) phx.gbl... This is a bit misleading, as the following are functionally equivalent: True. The main advantage of using, here, is it is more succinct and therefore faster to code. Indeed, which is why I recommended it... :-) |
|
Think outside the box! ************************************************* |
#9
| |||
| |||
|
|
I find too many cases where I temporary have to add a catch, so I am a creature of habit. ;-) |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |