内部.Net Framework数据提供程序错误1 [英] Internal .Net Framework Data Provider error 1
问题描述
我正在使用Visual Studio 2012 Ultimate Edition开发带有所有Service Pack,C#和.NET Framework 4.5的WinForm应用。
I'm developing a WinForm app with Visual Studio 2012 Ultimate edition with all service pack, C# and .NET Framework 4.5.
我遇到此异常:
Internal .Net Framework Data Provider error 1
使用此堆栈:
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()
在析构函数中:
~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;
}
}
我在第 this.conn.Close();
。
而 conn
是 private SqlConnection conn = null;
你知道为什么吗?
推荐答案
我已找到解决方案此处。
基本上可以归结为:
警告
Caution
请勿在以下方法的Finalize方法中调用关闭或丢弃连接,DataReader或任何其他托管对象你的班。在终结器中,您应该只释放类直接拥有的非托管资源。如果您的类不拥有任何非托管资源,请不要在类定义中包括Finalize方法。有关更多信息,请参见垃圾回收。
Do not call Close or Dispose on a Connection, a DataReader, or any other managed object in the Finalize method of your class. In a finalizer, you should only release unmanaged resources that your class owns directly. If your class does not own any unmanaged resources, do not include a Finalize method in your class definition. For more information, see Garbage Collection.
这篇关于内部.Net Framework数据提供程序错误1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!