内部 .Net Framework 数据提供程序错误 1 [英] Internal .Net Framework Data Provider error 1

查看:73
本文介绍了内部 .Net Framework 数据提供程序错误 1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Visual Studio 2012 Ultimate 版本开发一个 WinForm 应用程序,其中包含所有服务包、C# 和 .NET Framework 4.5.

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

I get the exception in line this.conn.Close();.

connprivate SqlConnection conn = null;

你知道为什么吗?

推荐答案

我找到了解决方案 这里.

基本上可以归结为:

注意

不要在类的 Finalize 方法中对 Connection、DataReader 或任何其他托管对象调用 Close 或 Dispose.在终结器中,您应该只释放您的类直接拥有的非托管资源.如果您的类不拥有任何非托管资源,请不要在类定义中包含 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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆