Add the Interface IDisposable to your class definition:
public class SqlDbConnection : IDisposable
Then add the Dispose method:
public void Dispose()
{
if (cmd != null)
{
cmd.Dispose();
cmd = null;
}
if (sda != null)
{
sda.Dispose();
sda = null;
}
if (dt != null)
{
dt.Dispose();
dt = null;
}
if (con != null)
{
if (con.State == ConnectionState.Open) con.Close();
con.Dispose();
con = null;
}
}
There is a good discussion on this here:
Implementing IDisposable and the Dispose Pattern Properly[
^] which is well worth a read.