Internal .Net Framework Data Provider error 1

A

Andrew

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.PrePush(Object
expectedOwner)
at
System.Data.ProviderBase.DbConnectionPool.PutObject(DbConnectionInternal
obj, Object owningObject)
at
System.Data.ProviderBase.DbConnectionInternal.CloseConnection(DbConnection
owningObject, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Close()
at System.Data.SqlClient.SqlConnection.Dispose(Boolean 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
 
J

Jeff Dillon

You should never hold onto a connection for the life of a page. Open and
close the connection each time you need to. Let Connection Pooling work for
you.

Jeff
 
A

Andrew

Thanks for the connection pooling tip. However in this case I'm not sure
how it's relevant. More detail on the cause of the error and whether
destructors should have exception handling code would be helpful.

Thanks,
Andrew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top