Command.Close vs Command.Dispose

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello All:

Can anyone tell me what the difference is between the Close method of the
OleDbCommand object and the Dispose method of the OleDbCommand object?

TIA,
 
Joe said:
Hello All:

Can anyone tell me what the difference is between the Close method of the
OleDbCommand object and the Dispose method of the OleDbCommand object?

TIA,

Dispose releases all the resources used by the object. Close just
releases the underlining connection so it can be used again for
something else.

Chris
 
Chris said:
Dispose releases all the resources used by the object. Close just
releases the underlining connection so it can be used again for
something else.

Chris

Um... On second though, the OleDbCommand object doesn't have a Close
method. My comments would be correct for a OleDbDataReader object though.

Chris
 
Thanks Chris. My question wasn't accurate, but you answered the spirit of it
anyway.
 
About dispose :

http://msdn.microsoft.com/library/d...l/frlrfsystemidisposableclassdisposetopic.asp

if a object contains a shutdown feature like close you must always
explicitly call it if you are finished with it

however if a component implements an idisposible interface you may call it
but it is not absolutely necesary as the GC wil call it for you


I use the following rule for good coding practice , for method level scoped
objects i never call a dispose method , however after the usage of a global
object ( global to the class ) that implements idisposible i do call it


p.s.
calling dispose multiple times will only result in coding overhead , and a
bigger executable in the end :-) , it does not hurt the performance as
idisposible has a boolean flag if it is / was called before on the current
object

regards

Michel Posseth [MCP]
 
Are you saying that you have to close a form before disposing of it? I use
form.dispose when I'm thru with the form and don't bother with the form.close
method unless I want to show the form again. Will I have a problem doing
this?
--
Dennis in Houston


m.posseth said:
About dispose :

http://msdn.microsoft.com/library/d...l/frlrfsystemidisposableclassdisposetopic.asp

if a object contains a shutdown feature like close you must always
explicitly call it if you are finished with it

however if a component implements an idisposible interface you may call it
but it is not absolutely necesary as the GC wil call it for you


I use the following rule for good coding practice , for method level scoped
objects i never call a dispose method , however after the usage of a global
object ( global to the class ) that implements idisposible i do call it


p.s.
calling dispose multiple times will only result in coding overhead , and a
bigger executable in the end :-) , it does not hurt the performance as
idisposible has a boolean flag if it is / was called before on the current
object

regards

Michel Posseth [MCP]
 
Dennis,

Just do it as Michel says, where however the modal form is on of the
exceptions which you have to dispose.

Howerver closing something end than disposing it is AFAIK stupid.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top