コード例 #1
0
        /// <summary>
        /// Opens a database connection with the property settings specified by the
        /// <see cref="Npgsql.NpgsqlConnection.ConnectionString">ConnectionString</see>.
        /// </summary>
        public override void Open()
        {
            CheckConnectionClosed();

            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Open");

            // Check if there is any missing argument.
            if (!settings.ContainsKey(Keywords.Host))
            {
                throw new ArgumentException(resman.GetString("Exception_MissingConnStrArg"),
                                            NpgsqlConnectionStringBuilder.GetKeyName(Keywords.Host));
            }
            if (!settings.ContainsKey(Keywords.UserName) && !settings.ContainsKey(Keywords.IntegratedSecurity))
            {
                throw new ArgumentException(resman.GetString("Exception_MissingConnStrArg"),
                                            NpgsqlConnectionStringBuilder.GetKeyName(Keywords.UserName));
            }

            // Get a Connector.  The connector returned is guaranteed to be connected and ready to go.
            connector = NpgsqlConnectorPool.ConnectorPoolMgr.RequestConnector(this);

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

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

            if (Enlist)
            {
                Promotable.Enlist(Transaction.Current);
            }
        }
コード例 #2
0
ファイル: NpgsqlConnection.cs プロジェクト: kswoll/Npgsql
        /// <summary>
        /// Opens a database connection with the property settings specified by the
        /// <see cref="Npgsql.NpgsqlConnection.ConnectionString">ConnectionString</see>.
        /// </summary>
        public override void Open()
        {
            // If we're postponing a close (see doc on this variable), the connection is already
            // open and can be silently reused
            if (_postponingClose)
            {
                return;
            }

            CheckConnectionClosed();

            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Open");

            // Check if there is any missing argument.
            if (!settings.ContainsKey(Keywords.Host))
            {
                throw new ArgumentException(resman.GetString("Exception_MissingConnStrArg"),
                                            NpgsqlConnectionStringBuilder.GetKeyName(Keywords.Host));
            }
            if (!settings.ContainsKey(Keywords.UserName) && !settings.ContainsKey(Keywords.IntegratedSecurity))
            {
                throw new ArgumentException(resman.GetString("Exception_MissingConnStrArg"),
                                            NpgsqlConnectionStringBuilder.GetKeyName(Keywords.UserName));
            }

            // Get a Connector, either from the pool or creating one ourselves.
            if (Pooling)
            {
                connector = NpgsqlConnectorPool.ConnectorPoolMgr.RequestConnector(this);
            }
            else
            {
                connector = new NpgsqlConnector(this);

                connector.RemoteCertificateValidationCallback += RemoteCertificateValidationCallback;
//                connector.ProvideClientCertificatesCallback += ProvideClientCertificatesCallbackDelegate;
//                connector.CertificateSelectionCallback += CertificateSelectionCallbackDelegate;
//                connector.CertificateValidationCallback += CertificateValidationCallbackDelegate;
//                connector.PrivateKeySelectionCallback += PrivateKeySelectionCallbackDelegate;
//                connector.ValidateRemoteCertificateCallback += ValidateRemoteCertificateCallbackDelegate;

                connector.Open();
            }

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

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

            if (Enlist)
            {
                Promotable.Enlist(Transaction.Current);
            }

            this.OnStateChange(new StateChangeEventArgs(ConnectionState.Closed, ConnectionState.Open));
        }
コード例 #3
0
        /// <summary>
        /// Opens a database connection with the property settings specified by the
        /// <see cref="NpgsqlConnection.ConnectionString">ConnectionString</see>.
        /// </summary>
        public override void Open()
        {
            // If we're postponing a close (see doc on this variable), the connection is already
            // open and can be silently reused
            if (_postponingClose)
            {
                return;
            }

            CheckConnectionClosed();

            _log.Debug("Opening connnection");

            // Check if there is any missing argument.
            if (!_settings.ContainsKey(Keywords.Host))
            {
                throw new ArgumentException(L10N.MissingConnStrArg, Keywords.Host.ToString());
            }
            if (!_settings.ContainsKey(Keywords.UserName) && !_settings.ContainsKey(Keywords.IntegratedSecurity))
            {
                throw new ArgumentException(L10N.MissingConnStrArg, Keywords.UserName.ToString());
            }

            // Get a Connector, either from the pool or creating one ourselves.
            if (Pooling)
            {
                Connector = NpgsqlConnectorPool.ConnectorPoolMgr.RequestConnector(this);
            }
            else
            {
                Connector = new NpgsqlConnector(this);

                Connector.ProvideClientCertificatesCallback += ProvideClientCertificatesCallbackDelegate;
                Connector.CertificateSelectionCallback      += CertificateSelectionCallbackDelegate;
                Connector.CertificateValidationCallback     += CertificateValidationCallbackDelegate;
                Connector.PrivateKeySelectionCallback       += PrivateKeySelectionCallbackDelegate;
                Connector.ValidateRemoteCertificateCallback += ValidateRemoteCertificateCallbackDelegate;

                Connector.Open();
            }

            Connector.Notice       += NoticeDelegate;
            Connector.Notification += NotificationDelegate;

            if (SyncNotification)
            {
                // Disable async notifications for now
                //Connector.AddNotificationThread();
            }

            if (Enlist)
            {
                Promotable.Enlist(Transaction.Current);
            }

            OnStateChange(new StateChangeEventArgs(ConnectionState.Closed, ConnectionState.Open));
        }
コード例 #4
0
ファイル: NpgsqlConnection.cs プロジェクト: mskalnik/revenj
        /// <summary>
        /// Opens a database connection with the property settings specified by the
        /// <see cref="Npgsql.NpgsqlConnection.ConnectionString">ConnectionString</see>.
        /// </summary>
        public override void Open()
        {
            CheckConnectionClosed();

            // Check if there is any missing argument.
            if (!settings.ContainsKey(Keywords.Host))
            {
                throw new ArgumentException("Connection string argument missing!",
                                            NpgsqlConnectionStringBuilder.GetKeyName(Keywords.Host));
            }
            if (!settings.ContainsKey(Keywords.UserName) && !settings.ContainsKey(Keywords.IntegratedSecurity))
            {
                throw new ArgumentException("Connection string argument missing!",
                                            NpgsqlConnectionStringBuilder.GetKeyName(Keywords.UserName));
            }

            // Get a Connector, either from the pool or creating one ourselves.
            if (Pooling)
            {
                connector = NpgsqlConnectorPool.ConnectorPoolMgr.RequestConnector(this);
            }
            else
            {
                connector = new NpgsqlConnector(this);

                connector.ProvideClientCertificatesCallback += ProvideClientCertificatesCallbackDelegate;
                connector.CertificateSelectionCallback      += CertificateSelectionCallbackDelegate;
                connector.CertificateValidationCallback     += CertificateValidationCallbackDelegate;
                connector.PrivateKeySelectionCallback       += PrivateKeySelectionCallbackDelegate;

                connector.Open();
            }

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

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

            if (Enlist)
            {
                Promotable.Enlist(Transaction.Current);
            }
            this.OnStateChange(new StateChangeEventArgs(ConnectionState.Closed, ConnectionState.Open));
        }
コード例 #5
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));
            }
        }
コード例 #6
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;

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

                NpgsqlConnectorPool.ConnectorPoolMgr.ReleaseConnector(this, connector);


                connector = null;
            }
        }
コード例 #7
0
 /// <summary>
 /// Enlist transation.
 /// </summary>
 /// <param name="transaction"></param>
 public override void EnlistTransaction(Transaction transaction)
 {
     Promotable.Enlist(transaction);
 }