What is the difference between Closing a database connection and Disposing a database connection?And why we must Dispose an external resource like database connection?

 Posted by Niladri.Biswas on 7/15/2012 | Category: C# Interview questions | Views: 2336 | Points: 40

We can reopen it later if we close a database connection. But if we Dispose a database connection we cannot use it anymore.We must create a new database object.

We must invoke Dispose method or Using statement whenever we have to free external resources. Else we may encounter the below error

An exception of type 'System.InvalidOperationException' occurred in System.Data.dll but was not handled in user code Additional information: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response