I have an SQL class that connects to a database and returns a DataTable. I know that SqlConnection should be removed at the end. I know that this can be done with a block using, but is it also acceptable to call Dispose()inside the destructor of this class?
Herre is my code:
public class SQLEng
{
public string ConnectionString{ get; set; }
SqlConnection _Conn;
public SQLEng(string connectionString)
{
ConnectionString = connectionString;
_Conn = new SqlConnection(connectionString);
}
public ~SQLEng()
{
_Conn.Dispose();
}
}
Basically, I want to have a variable of the SqlConnection class, and not create an instance of SqlConnection inside each method that accesses the database. Is this practice sound?
source
share