即使我调用dispose方法释放了已初始化的OleDbException,我的代码仍然没有释放文件句柄。有没有办法明确强制程序释放文件句柄?
Close()
和Dispose()
只是将连接释放回池中,而不是强制关闭它。最终它会超时并从池中关闭。OLE DB Services = -2;
,这应该为您提供除了池化之外的所有服务OleDBConnection.ReleaseObjectPool()
不确定为什么您的代码在调用Dispose()后没有关闭句柄,因为它在幕后调用Close(),但以下内容可能会帮助您以常见的方式编写代码:
using (OleDbConnection conn = new OleDbConnection(connString))
{
//your stuff here
conn.Close(); //not necessary, but doesn't hurt
}