G
Guest
Hello, Newsgroupians:
I am creating a wrapper for (I)DbConnection. I can connect to a database
and place queries; however, I'm having some problems with my wrapped class.
In short, I have the following...
public class CDB
{
protected System.Data.IDbConnection m_conn;
...
}
Now, I've read that I should ALWAYS close my connection when I'm finished.
So when my class that wraps the connection is ready for garbage collection, I
close the connection in the destructor. It is as follows...
~CDB()
{
if (this.m_conn.State == System.Data.ConnectionState.Open)
{
try
{
this.m_conn.Close();
}
catch(Exception e)
{
Console.WriteLine(e.Message);
Console.ReadLine(); // I add this just so I can see the message.
}
}
}
The problem is I always receive the exception -- which is an
InvalidOperationException -- "Handle is not initialized." Any ideas what I
am doing wrong, or how to rectify the situation? Thank you. Should you need
more of my code, please do not hesistate to ask. I just thought the other
code was irrelevant in this situation. Thank you again.
Trecius
I am creating a wrapper for (I)DbConnection. I can connect to a database
and place queries; however, I'm having some problems with my wrapped class.
In short, I have the following...
public class CDB
{
protected System.Data.IDbConnection m_conn;
...
}
Now, I've read that I should ALWAYS close my connection when I'm finished.
So when my class that wraps the connection is ready for garbage collection, I
close the connection in the destructor. It is as follows...
~CDB()
{
if (this.m_conn.State == System.Data.ConnectionState.Open)
{
try
{
this.m_conn.Close();
}
catch(Exception e)
{
Console.WriteLine(e.Message);
Console.ReadLine(); // I add this just so I can see the message.
}
}
}
The problem is I always receive the exception -- which is an
InvalidOperationException -- "Handle is not initialized." Any ideas what I
am doing wrong, or how to rectify the situation? Thank you. Should you need
more of my code, please do not hesistate to ask. I just thought the other
code was irrelevant in this situation. Thank you again.
Trecius