void Close() { OdbcReturn ret = OdbcReturn.Error; if (State == ConnectionState.Open) { lock (this) { // close any associated commands // NOTE: we may 'miss' some if the garbage collector has // already started to destroy them. if (linkedCommands != null) { for (int i = 0; i < linkedCommands.Count; i++) { WeakReference wr = (WeakReference)linkedCommands [i]; if (wr == null) { continue; } OdbcCommand c = (OdbcCommand)wr.Target; if (c != null) { c.Unlink(); } } linkedCommands = null; } // disconnect ret = libodbc.SQLDisconnect(hdbc); } // There could be OdbcCommands outstanding (see NOTE above); their // hstmts will have been freed and therefore will be invalid. // However, they will find that their definition of Generation // does not match the connection's, so they won't try and free // those hstmt. if ((ret != OdbcReturn.Success) && (ret != OdbcReturn.SuccessWithInfo)) { throw CreateOdbcException(OdbcHandleType.Dbc, hdbc); } FreeHandles(); transaction = null; RaiseStateChange(ConnectionState.Open, ConnectionState.Closed); } }
void Close() { OdbcReturn ret = OdbcReturn.Error; if (State == ConnectionState.Open) { // close any associated commands if (linkedCommands != null) { for (int i = 0; i < linkedCommands.Count; i++) { WeakReference wr = (WeakReference)linkedCommands [i]; if (wr == null) { continue; } OdbcCommand c = (OdbcCommand)wr.Target; if (c != null) { c.Unlink(); } } linkedCommands = null; } // disconnect ret = libodbc.SQLDisconnect(hdbc); if ((ret != OdbcReturn.Success) && (ret != OdbcReturn.SuccessWithInfo)) { throw CreateOdbcException(OdbcHandleType.Dbc, hdbc); } FreeHandles(); transaction = null; RaiseStateChange(ConnectionState.Open, ConnectionState.Closed); } }