Van*_*nel 13 .net c# ado.net destructor
我正在使用Visual Studio 2012 Ultimate版本开发一个带有所有Service Pack,C#和.NET Framework 4.5的WinForm应用程序.
我得到这个例外:
Internal .Net Framework Data Provider error 1
Run Code Online (Sandbox Code Playgroud)
有了这个堆栈:
en System.Data.ProviderBase.DbConnectionInternal.PrePush(Object expectedOwner)
en System.Data.ProviderBase.DbConnectionPool.PutObject(DbConnectionInternal obj, Object owningObject)
en System.Data.ProviderBase.DbConnectionInternal.CloseConnection(DbConnection owningObject, DbConnectionFactory connectionFactory)
en System.Data.SqlClient.SqlConnection.CloseInnerConnection()
en System.Data.SqlClient.SqlConnection.Close()
en AdoData.TRZIC.DisposeCurrentConnection()
en AdoData.TRZIC.Finalize()
Run Code Online (Sandbox Code Playgroud)
在析构函数中:
~TRZIC()
{
DisposeCurrentConnection();
if (this.getCodeCmd != null)
this.getCodeCmd.Dispose();
}
private void DisposeCurrentConnection()
{
if (this.conn != null)
{
if (this.conn.State == ConnectionState.Open)
this.conn.Close();
this.conn.Dispose();
this.conn = null;
}
}
Run Code Online (Sandbox Code Playgroud)
我得到了例外this.conn.Close();
.
而且conn
是private SqlConnection conn = null;
你知道为什么吗?