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
what are windows services?
Can derived classes have greater accessibility than their base types?
What is the difference between string and string in c#?
What is dependency injection?
What Happens In Memory When You Box And Unbox A Value-type?
What is a custom attribute?
What type of data type conversion happens when the compiler encounters the following code?
What is sqladapter c#?
What is an indexer in c#?
What is the difference between ref and out parameters in c#?
what is the difference between a struct and a class in c#?
How do I calculate relative time?
What are the 3 different types of arrays?
Is multiple inheritance possible in c#?
How does c# achieve polymorphism?