I had a suspicion that the database connection used in one of our applications is not always closed. I went to see the code, and I found a class DataProviderthat has an object SqlConnection. The connection is opened in the constructor of this class and closed in it by the method Dispose(do not judge that I know that maintaining an open connection is evil, it’s just not my code, and this is not a question question). The method Disposeis implemented as follows:
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
if (disposing)
{
if (_conn != null)
_conn.Close();
}
_disposed = true;
}
}
Question:
Does this always guarantee closing the connection?
Is this code correct?
I think that there should be _conn.Dispose(), which is called - I'm right, and can this affect the non-closure of the connection (maybe not)?