示例#1
0
        /// <summary>
        /// Releases the connection to the database.  If the connection is pooled, it will be
        ///	made available for re-use.  If it is non-pooled, the actual connection will be shutdown.
        /// </summary>
        public override void Close()
        {
            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Close");

            if (connector != null)
            {
                Promotable.Prepare();
                // clear the way for another promotable transaction
                promotable = null;

                connector.Notification -= NotificationDelegate;
                connector.Notice       -= NoticeDelegate;
                connector.StateChanged -= connector_StateChanged;

                if (SyncNotification)
                {
                    connector.RemoveNotificationThread();
                }

                if (Pooling)
                {
                    NpgsqlConnectorPool.ConnectorPoolMgr.ReleaseConnector(this, connector);
                }
                else
                {
                    Connector.ProvideClientCertificatesCallback -= ProvideClientCertificatesCallbackDelegate;
                    Connector.CertificateSelectionCallback      -= CertificateSelectionCallbackDelegate;
                    Connector.CertificateValidationCallback     -= CertificateValidationCallbackDelegate;
                    Connector.PrivateKeySelectionCallback       -= PrivateKeySelectionCallbackDelegate;

                    if (Connector.Transaction != null)
                    {
                        Connector.Transaction.Cancel();
                    }

                    Connector.Close();
                }


                connector = null;

                this.OnStateChange(new StateChangeEventArgs(ConnectionState.Open, ConnectionState.Closed));
            }
        }
        /// <summary>
        /// Releases the connection to the database.  If the connection is pooled, it will be
        ///	made available for re-use.  If it is non-pooled, the actual connection will be shutdown.
        /// </summary>
        public override void Close()
        {
            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Close");

            if (connector != null)
            {
                Promotable.Prepare();
                // clear the way for another promotable transaction
                promotable = null;

                connector.Notification -= NotificationDelegate;
                connector.Notice       -= NoticeDelegate;

                if (SyncNotification)
                {
                    connector.RemoveNotificationThread();
                }

                NpgsqlConnectorPool.ConnectorPoolMgr.ReleaseConnector(this, connector);


                connector = null;
            }
        }