What does Dispose method do with the connection object?
Answer Posted / abhishek
SqlConnection.Dispose - in addition to closing the connection, it also
clears stateful nature of the SqlConnection instance, like connection string
etc.Beneath this layer, in SqlConnection atleast, there is a connection
pooling mechanism, which eventually holds actual physical database
connections. Again, they aren't really unmanaged resources, but non .NET
resources nonetheless. Lest I cause any confusion SqlClient has TDS parsing
built into .NET code, so technically in this scenario - there wasn't any
unmanaged resource.
So in short, Dispose does not **have** to release unmanaged resources - and
by convention it does cleanup. Thats exactly what SqlConnection.Dispse
does - "clean up clean up everybody do your share"
| Is This Answer Correct ? | 3 Yes | 1 No |
Post New Answer View All Answers
Should I make my destructor virtual?
Explain how to parse a datetime string?
What are destructors in C#?
What is monitor in C#?
Can a struct inherit from another struct or class in c#?
Explain the ways to deploy an assembly?
How do I create multifile assembly?
Does c# have its own class library?
explain the three services model commonly know as a three-tier application.
What is a linq in c#?
What is a variable in c#?
Where do we set the min and max pool size for connection pooling?
What is the difference between c and c sharp?
What is type keyword in c#?
What is constructor overloading in c#?