Ejemplo n.º 1
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("Connection string argument missing", Keywords.Host.ToString());
            }
            if (!_settings.ContainsKey(Keywords.UserName) && !_settings.ContainsKey(Keywords.IntegratedSecurity))
            {
                throw new ArgumentException("Connection string argument missing", 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.ValidateRemoteCertificateCallback += ValidateRemoteCertificateCallbackDelegate;

                Connector.Open();
            }

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

            /*if (SyncNotification)
             * {
             *
             * }*/

#if !DNXCORE50
            if (Enlist)
            {
                Promotable.Enlist(Transaction.Current);
            }
#endif

            OpenCounter++;
            OnStateChange(new StateChangeEventArgs(ConnectionState.Closed, ConnectionState.Open));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Enlist transation.
 /// </summary>
 /// <param name="transaction"></param>
 public override void EnlistTransaction(Transaction transaction)
 {
     Promotable.Enlist(transaction);
 }
Ejemplo n.º 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 (string.IsNullOrWhiteSpace(Host))
            {
                throw new ArgumentException("Host can't be null");
            }
            if (string.IsNullOrWhiteSpace(Database))
            {
                throw new ArgumentException("Database can't be null");
            }
            if (string.IsNullOrWhiteSpace(UserName) && !IntegratedSecurity)
            {
                throw new ArgumentException("Either Username must be specified or IntegratedSecurity must be on");
            }
            Contract.EndContractBlock();

            // 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");

            WasBroken = false;

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

                    Connector.Open();
                }

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

#if !DNXCORE50
                if (Enlist)
                {
                    Promotable.Enlist(Transaction.Current);
                }
#endif
            }
            catch
            {
                Connector = null;
                throw;
            }
            OpenCounter++;
            OnStateChange(new StateChangeEventArgs(ConnectionState.Closed, ConnectionState.Open));
        }