【发布时间】:2014-07-16 18:37:04
【问题描述】:
我正在使用此代码:
public class SQLConnection : IConnection
{
private SqlConnection _sqlConnection = null;
//bunch of interface implementations for my project
//the destructor
~SQLConnection()
{
if(_sqlConnection != null)
{
if(_sqlConnection.State == ConnectionState.Open)
{
_sqlConnection.Close();
}
_sqlConnection.Dispose();
}
}
}
这一直很好,直到前一段时间我开始收到此错误:Internal .Net Framework Data Provider error 1
在谷歌搜索了一下之后,我找到了this link(警告部分),我认为这就是发生在我身上的事情。
我的班级每次都在管理连接状态的打开和关闭,但现在我似乎无法以这种方式管理它,有没有其他方法可以做到这一点,而无需访问我使用连接的每个功能和显式调用connection.Close()?
【问题讨论】:
标签: c# sql connection