Win2k3
IIS6
..NET 2.0
In my ASP.NET 2.0 app I create an open an SQL connection in the page's
constructor and call objSQL.Dispose() in the destructor. The SQLConnection
object is a class member of the page. Here's the destructor code:
/// Destructor
~Officer()
{
if( m_objConn != null )
m_objConn.Dispose();
}
/// End Destructor
When running this particular page through some testing I get the following
exception in the destructor at the "m_objConn.Dispose();" line:
System.InvalidOperationException was unhandled
Message="Internal .Net Framework Data Provider error 1."
Source="System.Data"
StackTrace:
at System.Data.ProviderBase.DbConnectionInternal.PreP ush(Object
expectedOwner)
at
System.Data.ProviderBase.DbConnectionPool.PutObjec t(DbConnectionInternal
obj, Object owningObject)
at
System.Data.ProviderBase.DbConnectionInternal.Clos eConnection(DbConnection
owningObject, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Close()
at System.Data.SqlClient.SqlConnection.Dispose(Boolea n disposing)
at System.ComponentModel.Component.Dispose()
at Officer.Finalize() in c:\sys\projects\AddOfficer.aspx.cs:line 46
When I stop debugging VS2k5 pops up the JIT debugging dialog stating an
unhandled exception occurred in w3wp.exe.
1) Is this a bug?
2) Do I need a try/catch in a destructor? Is it good programming practice?
3) Why is this happening?
4) What is the meaning of life?
Any help is appreciated. TIA
Andrew