gpt4 book ai didi

c# - 内部 .Net Framework 数据提供程序错误 1

转载 作者:可可西里 更新时间:2023-11-01 08:20:54 24 4
gpt4 key购买 nike

我正在使用带有所有服务包、C# 和 .NET Framework 4.5 的 Visual Studio 2012 Ultimate 版开发 WinForm 应用。

我得到这个异常:

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(); 行得到异常。

connprivate SqlConnection conn = null;

你知道为什么吗?

最佳答案

我找到了解决方案 here .

基本上可以归结为:

Caution

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.

关于c# - 内部 .Net Framework 数据提供程序错误 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22962742/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com