I wrote a class that inherits DbConnection and I'm not understanding fully why it works as it does.
At first I had this :
public class DatabaseConnection : DbConnection
{
...
public override void Close()
{
// Some stuff
}
// No Dispose method
}
using(var db = new DatabaseConnection())
{
// Some processing
}
The Close() method was not called, and we could see the connections staying on the MySQL server.
Now I have this, and it works (it really closes the connections, and the server is OK) :
public class DatabaseConnection : DbConnection, IDisposable
{
...
public override void Close()
{
// Some stuff
}
public new void Dispose()
{
Close();
base.Dispose();
GC.SuppressFinalize(this);
}
}
using(var db = new DatabaseConnection())
{
// Some processing
}
Why inheriting the DbConnection class and overriding the Close() method doesn't work ?