the difference betweenSqlConnection.IDisposable.Dispose() andSqlConnection.Dispose().

  • Thread starter Thread starter tangyong
  • Start date Start date
T

tangyong

All:
I have a question about the difference between
SqlConnection.IDisposable.Dispose() and SqlConnection.Dispose(). Both of them realize the function of releasing the connection to the ConnectionPool? Do they have the same effection source code? If they are different, who can tell me the differences? If they are same, why MS gives the SqlConnection.IDisposable.Dispose,but only SqlConnection.Dispose() method?
In the MSDN, there are following description about the
SqlConnection.IDisposable.Dispose Method:
"This member supports the .NET Framework infrastructure and is not intended to be used directly from your code." what's the meaning of it?
If the user has called the SqlConnection.IDisposable.Dispose() in the client application, what probem results in? and if there are some problem becomes, then why did MS give us such a method?
in the same, who can tell me the using of
"SqlConnection.ICloneable.Clone "
"SqlConnection.IDbConnection.BeginTransaction" and
"SqlConnection.IDbConnection.CreateCommand"?

Best Regards!!
 
I think if you leave out the interface name, the compiler will choose the
most sensible one for you (usually the object itself's implementation).

If you explicitly selected to call through an interface name, you risk to do
things wrong by chance the object itself choosen to override the method to
do other things. For the purpose of SqlConnection.Dispose(), the object may
have allocated some other resource that require to be freed on dispose, may
need to ensure all datareaders/dataadapeters or so have been properly closed
or so, while IDisposable.Dispose seems to just free up the object (and other
object's in it)'s memory.
 
Back
Top