OdbcConnection.ReleaseObjectPool 方法
定义
指示当释放最后的基础连接时可以释放 ODBC 驱动程序管理器环境句柄。Indicates that the ODBC Driver Manager environment handle can be released when the last underlying connection is released.
public:
static void ReleaseObjectPool();
public static void ReleaseObjectPool ();
static member ReleaseObjectPool : unit -> unit
Public Shared Sub ReleaseObjectPool ()
注解
ReleaseObjectPool 可以调用来释放 ODBC 环境句柄。ReleaseObjectPool can be called to release the ODBC environment handle. 例如,如果不会再次使用连接对象,则可能需要调用此方法。You might want to call this method if, for example, the connection object will not be used again. 在环境中的所有连接都关闭后,就可以释放环境了。When all connections in the environment are closed, the environment can be disposed. 请注意,单独调用方法并不会实际释放环境中存在的活动连接。Note that calling the method alone does not actually release the active connections that exist in the environment.
在最终释放环境之前,必须执行以下操作:The following must occur before the environment is finally disposed:
调用 Close 以 OdbcConnection 从环境中释放对象。Call Close to release the OdbcConnection object from the environment.
允许每个连接对象超时。Allow each connection object to time out.
调用 ReleaseObjectPool。Call ReleaseObjectPool.
调用垃圾回收。Invoke garbage collection.
相反,如果您 Close 对所有活动连接调用,并调用垃圾回收,但不调用 ReleaseObjectPool ,则为环境保留的资源仍可用。Conversely, if you call Close on all active connections, and invoke garbage collection, but do not call ReleaseObjectPool, the resources reserved for the environment remain available.
环境句柄发布后,新的请求会 OdbcConnection 创建新的环境。After an environment handle is released, a request for a new OdbcConnection creates a new environment.