Exemplo n.º 1
0
        // this constructor is called by the implicit object pooler
        public SqlInternalConnection(SqlConnectionString connectionOptions, ConnectionPool pool, bool fCheckLifetime, TimeSpan lifetime,
                                     bool fResetConnection, string originalDatabase, string originalLanguage)
        {
            // clone the hashtable, since this is pooled - should not use same reference
            _connectionOptions = connectionOptions.Clone();

            _fIsPooled        = true;
            _pool             = pool;
            _fCheckLifetime   = fCheckLifetime;
            _lifetime         = lifetime;
            _fResetConnection = fResetConnection;
            _originalDatabase = originalDatabase;
            _originalLanguage = originalLanguage;

            this.OpenAndLogin();

            // PerfCounters
            SQL.IncrementPooledConnectionCount();
            SQL.PossibleIncrementPeakPoolConnectionCount();

            // let activate handle distributed transaction enlistment

            // obtain the time of construction, if fCheckLifetime
            if (_fCheckLifetime)
            {
                _createTime = DateTime.UtcNow;
            }
        }
Exemplo n.º 2
0
        public SqlConnectionPoolControl(String key, bool integratedSecurity, IntPtr SID, IntPtr tokenStruct, SqlConnectionString connectionOptions) : base(key, integratedSecurity, SID, tokenStruct)
        {
            // CreationTimeout is in milliseconds, Connection Timeout is in seconds, but don't set it to > MaxValue
            CreationTimeout = connectionOptions.ConnectTimeout;
            if ((0 < CreationTimeout) && (CreationTimeout < Int32.MaxValue / 1000))
            {
                CreationTimeout *= 1000;
            }
            else if (CreationTimeout >= Int32.MaxValue / 1000)
            {
                CreationTimeout = Int32.MaxValue;
            }
            MaxPool             = connectionOptions.MaxPoolSize;
            MinPool             = connectionOptions.MinPoolSize;
            TransactionAffinity = connectionOptions.Enlist;

            _connectionOptions = connectionOptions.Clone();

            int lifetime = connectionOptions.ConnectionLifeTime;

            // Initialize the timespan class for the pool control, if it's not zero.
            // If it was zero - that means infinite lifetime.
            if (lifetime != 0)
            {
                _fCheckLifetime = true;
                _lifetime       = new TimeSpan(0, 0, lifetime);
            }

            // if reset is specified, obtain variables
            if (_connectionOptions.ConnectionReset)
            {
                _fResetConnection = true;
                _originalDatabase = _connectionOptions.InitialCatalog;
                _originalLanguage = _connectionOptions.CurrentLanguage;
            }
        }