This question has to do with this post and some of the answers, especially the answer from @EricLippert .
I want to encapsulate reading and writing an Informix SE database inside of a C# class.
I want the OdbcConnection
, OdbcCommand
, and OdbcDataReader
to be created when a class method is called, and remain as long as the class instance is active. I am assuming I need a C# finalizer to do this.
I believe that merely instantiating C# class in a using statement won't dispose what a class method creates. For example, I would need a finalizer in the following to make sure that m_dbCon
gets cleaned up, when the class leaves the scope of the using
statement.
Is this correct?
class icsDbIo
{
private OdbcConnection m_dbCon;
private OdbcCommand m_dbCmd;
private OdbcDataReader m_dbReader;
private string m_queryString;
private string m_dsn;
public OdbcDataReader connectAndReturnDataReader()
{
m_dbCon = new OdbcConnection("DSN=bucky");
.
.
.
return m_dbReader;
}