internal DbConnectionPoolGroup(System.Data.Common.DbConnectionOptions connectionOptions, System.Data.ProviderBase.DbConnectionPoolGroupOptions poolGroupOptions)
 {
     this._connectionOptions = connectionOptions;
     this._poolGroupOptions = poolGroupOptions;
     this._poolCollection = new HybridDictionary(1, false);
     this._state = 1;
 }
 internal DbConnectionPoolGroup(DbConnectionOptions connectionOptions, DbConnectionPoolGroupOptions poolGroupOptions)
 {
     this._connectionOptions = connectionOptions;
     this._poolGroupOptions = poolGroupOptions;
     this._poolCollection = new HybridDictionary(1, false);
     this._state = 1;
 }
Exemplo n.º 3
0
        private void ConnectionString_Set(string value)
        {
            System.Data.Common.DbConnectionOptions         userConnectionOptions = null;
            System.Data.ProviderBase.DbConnectionPoolGroup group           = this.ConnectionFactory.GetConnectionPoolGroup(value, null, ref userConnectionOptions);
            System.Data.ProviderBase.DbConnectionInternal  innerConnection = this.InnerConnection;
            bool allowSetConnectionString = innerConnection.AllowSetConnectionString;

            if (allowSetConnectionString)
            {
                allowSetConnectionString = this.SetInnerConnectionFrom(System.Data.ProviderBase.DbConnectionClosedBusy.SingletonInstance, innerConnection);
                if (allowSetConnectionString)
                {
                    this._userConnectionOptions = userConnectionOptions;
                    this._poolGroup             = group;
                    this._innerConnection       = System.Data.ProviderBase.DbConnectionClosedNeverOpened.SingletonInstance;
                }
            }
            if (!allowSetConnectionString)
            {
                throw System.Data.Common.ADP.OpenConnectionPropertySet("ConnectionString", innerConnection.State);
            }
            if (Bid.TraceOn)
            {
                string str = (userConnectionOptions != null) ? userConnectionOptions.UsersConnectionStringForTrace() : "";
                Bid.Trace("<prov.DbConnectionHelper.ConnectionString_Set|API> %d#, '%ls'\n", this.ObjectID, str);
            }
        }
Exemplo n.º 4
0
 internal DbConnectionPoolGroup(System.Data.Common.DbConnectionOptions connectionOptions, System.Data.ProviderBase.DbConnectionPoolGroupOptions poolGroupOptions)
 {
     this._connectionOptions = connectionOptions;
     this._poolGroupOptions  = poolGroupOptions;
     this._poolCollection    = new HybridDictionary(1, false);
     this._state             = 1;
 }
 protected DbConnectionOptions(DbConnectionOptions connectionOptions)
 {
     this._usersConnectionString = connectionOptions._usersConnectionString;
     this.HasPasswordKeyword = connectionOptions.HasPasswordKeyword;
     this.UseOdbcRules = connectionOptions.UseOdbcRules;
     this._parsetable = connectionOptions._parsetable;
     this.KeyChain = connectionOptions.KeyChain;
 }
 internal DBDataPermission(DbConnectionOptions connectionOptions)
 {
     this._keyvaluetree = NameValuePermission.Default;
     if (connectionOptions != null)
     {
         this._allowBlankPassword = connectionOptions.HasBlankPassword;
         this.AddPermissionEntry(new DBConnectionString(connectionOptions));
     }
 }
Exemplo n.º 7
0
 internal void PermissionDemand()
 {
     System.Data.ProviderBase.DbConnectionPoolGroup poolGroup = this.PoolGroup;
     System.Data.Common.DbConnectionOptions         options   = (poolGroup != null) ? poolGroup.ConnectionOptions : null;
     if ((options == null) || options.IsEmpty)
     {
         throw System.Data.Common.ADP.NoConnectionString();
     }
     this.UserConnectionOptions.DemandPermission();
 }
Exemplo n.º 8
0
 public static void ClearPool(OracleConnection connection)
 {
     System.Data.Common.ADP.CheckArgumentNull(connection, "connection");
     System.Data.Common.DbConnectionOptions userConnectionOptions = connection.UserConnectionOptions;
     if (userConnectionOptions != null)
     {
         userConnectionOptions.DemandPermission();
         OracleConnectionFactory.SingletonInstance.ClearPool(connection);
     }
 }
Exemplo n.º 9
0
        private DBConnectionString(DbConnectionOptions connectionOptions, string restrictions, KeyRestrictionBehavior behavior, Hashtable synonyms, bool mustCloneDictionary)
        {
            Debug.Assert(null != connectionOptions, "null connectionOptions");
            switch (behavior)
            {
                case KeyRestrictionBehavior.PreventUsage:
                case KeyRestrictionBehavior.AllowOnly:
                    _behavior = behavior;
                    break;
                default:
                    throw ADP.InvalidKeyRestrictionBehavior(behavior);
            }

            // grab all the parsed details from DbConnectionOptions
            _encryptedUsersConnectionString = connectionOptions.UsersConnectionString(false);
            _hasPassword = connectionOptions._hasPasswordKeyword;
            _parsetable = connectionOptions.Parsetable;
            _keychain = connectionOptions._keyChain;

            // we do not want to serialize out user password unless directed so by "persist security info=true"
            // otherwise all instances of user's password will be replaced with "*"
            if (_hasPassword && !connectionOptions.HasPersistablePassword)
            {
                if (mustCloneDictionary)
                {
                    // clone the hashtable to replace user's password/pwd value with "*"
                    // we only need to clone if coming from DbConnectionOptions and password exists
                    _parsetable = (Hashtable)_parsetable.Clone();
                }

                // different than Everett in that instead of removing password/pwd from
                // the hashtable, we replace the value with '*'.  This is okay since we
                // serialize out with '*' so already knows what we do.  Better this way
                // than to treat password specially later on which causes problems.
                const string star = "*";
                if (_parsetable.ContainsKey(KEY.Password))
                {
                    _parsetable[KEY.Password] = star;
                }
                if (_parsetable.ContainsKey(KEY.Pwd))
                {
                    _parsetable[KEY.Pwd] = star;
                }

                // replace user's password/pwd value with "*" in the linked list and build a new string
                _keychain = connectionOptions.ReplacePasswordPwd(out _encryptedUsersConnectionString, true);
            }

            if (!string.IsNullOrEmpty(restrictions))
            {
                _restrictionValues = ParseRestrictions(restrictions, synonyms);
                _restrictions = restrictions;
            }
        }
Exemplo n.º 10
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         this._userConnectionOptions = null;
         this._poolGroup             = null;
         this.Close();
     }
     this.DisposeMe(disposing);
     base.Dispose(disposing);
 }
Exemplo n.º 11
0
        private string ConnectionString_Get()
        {
            Bid.Trace("<prov.DbConnectionHelper.ConnectionString_Get|API> %d#\n", this.ObjectID);
            bool shouldHidePassword = this.InnerConnection.ShouldHidePassword;

            System.Data.Common.DbConnectionOptions userConnectionOptions = this.UserConnectionOptions;
            if (userConnectionOptions == null)
            {
                return("");
            }
            return(userConnectionOptions.UsersConnectionString(shouldHidePassword));
        }
 private System.Data.ProviderBase.DbConnectionPool GetConnectionPool(DbConnection owningObject, System.Data.ProviderBase.DbConnectionPoolGroup connectionPoolGroup)
 {
     if (connectionPoolGroup.IsDisabled && (connectionPoolGroup.PoolGroupOptions != null))
     {
         Bid.Trace("<prov.DbConnectionFactory.GetConnectionPool|RES|INFO|CPOOL> %d#, DisabledPoolGroup=%d#\n", this.ObjectID, connectionPoolGroup.ObjectID);
         System.Data.ProviderBase.DbConnectionPoolGroupOptions poolGroupOptions = connectionPoolGroup.PoolGroupOptions;
         System.Data.Common.DbConnectionOptions connectionOptions = connectionPoolGroup.ConnectionOptions;
         string connectionString = connectionOptions.UsersConnectionString(false);
         connectionPoolGroup = this.GetConnectionPoolGroup(connectionString, poolGroupOptions, ref connectionOptions);
         this.SetConnectionPoolGroup(owningObject, connectionPoolGroup);
     }
     return(connectionPoolGroup.GetConnectionPool(this));
 }
 internal System.Data.ProviderBase.DbConnectionInternal CreateNonPooledConnection(DbConnection owningConnection, System.Data.ProviderBase.DbConnectionPoolGroup poolGroup)
 {
     System.Data.Common.DbConnectionOptions connectionOptions = poolGroup.ConnectionOptions;
     System.Data.ProviderBase.DbConnectionPoolGroupProviderInfo providerInfo = poolGroup.ProviderInfo;
     System.Data.ProviderBase.DbConnectionInternal internal2 = this.CreateConnection(connectionOptions, providerInfo, null, owningConnection);
     if (internal2 != null)
     {
         this.PerformanceCounters.HardConnectsPerSecond.Increment();
         internal2.MakeNonPooledObject(owningConnection, this.PerformanceCounters);
     }
     Bid.Trace("<prov.DbConnectionFactory.CreateNonPooledConnection|RES|CPOOL> %d#, Non-pooled database connection created.\n", this.ObjectID);
     return(internal2);
 }
Exemplo n.º 14
0
 private void CopyFrom(OracleConnection connection)
 {
     System.Data.Common.ADP.CheckArgumentNull(connection, "connection");
     this._userConnectionOptions = connection.UserConnectionOptions;
     this._poolGroup             = connection.PoolGroup;
     if (System.Data.ProviderBase.DbConnectionClosedNeverOpened.SingletonInstance == connection._innerConnection)
     {
         this._innerConnection = System.Data.ProviderBase.DbConnectionClosedNeverOpened.SingletonInstance;
     }
     else
     {
         this._innerConnection = System.Data.ProviderBase.DbConnectionClosedPreviouslyOpened.SingletonInstance;
     }
 }
Exemplo n.º 15
0
        private void CopyFrom(SqlConnection connection)
        {
            ADP.CheckArgumentNull(connection, "connection");
            _userConnectionOptions = connection.UserConnectionOptions;
            _poolGroup = connection.PoolGroup;

            if (DbConnectionClosedNeverOpened.SingletonInstance == connection._innerConnection)
            {
                _innerConnection = DbConnectionClosedNeverOpened.SingletonInstance;
            }
            else
            {
                _innerConnection = DbConnectionClosedPreviouslyOpened.SingletonInstance;
            }
        }
        private const int PoolGroupStateDisabled = 4; // factory pool entry prunning method

        internal DbConnectionPoolGroup (DbConnectionOptions connectionOptions, DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolGroupOptions) {
            Debug.Assert(null != connectionOptions, "null connection options");
            Debug.Assert(null == poolGroupOptions || ADP.IsWindowsNT, "should not have pooling options on Win9x");

            _connectionOptions = connectionOptions;
            _poolKey = key;
            _poolGroupOptions = poolGroupOptions;

            // always lock this object before changing state
            // HybridDictionary does not create any sub-objects until add
            // so it is safe to use for non-pooled connection as long as
            // we check _poolGroupOptions first
            _poolCollection = new ConcurrentDictionary<DbConnectionPoolIdentity, DbConnectionPool>();
            _state = PoolGroupStateActive; // VSWhidbey 112102
        }
Exemplo n.º 17
0
 // Copy Constructor
 private void CopyFrom(CONNECTIONOBJECTNAME connection) { // V1.2.3300
     ADP.CheckArgumentNull(connection, "connection");
     _userConnectionOptions = connection.UserConnectionOptions;
     _poolGroup = connection.PoolGroup;
     
     // SQLBU 432115
     //  Match the original connection's behavior for whether the connection was never opened,
     //  but ensure Clone is in the closed state.
     if (DbConnectionClosedNeverOpened.SingletonInstance == connection._innerConnection)
     {
         _innerConnection = DbConnectionClosedNeverOpened.SingletonInstance;
     }
     else
     {
         _innerConnection = DbConnectionClosedPreviouslyOpened.SingletonInstance;
     }
 }
Exemplo n.º 18
0
 private void ConnectionString_Set(DbConnectionPoolKey key)
 {
     DbConnectionOptions connectionOptions = null;
     System.Data.ProviderBase.DbConnectionPoolGroup poolGroup = ConnectionFactory.GetConnectionPoolGroup(key, null, ref connectionOptions);
     DbConnectionInternal connectionInternal = InnerConnection;
     bool flag = connectionInternal.AllowSetConnectionString;
     if (flag)
     {
         flag = SetInnerConnectionFrom(DbConnectionClosedBusy.SingletonInstance, connectionInternal);
         if (flag)
         {
             _userConnectionOptions = connectionOptions;
             _poolGroup = poolGroup;
             _innerConnection = DbConnectionClosedNeverOpened.SingletonInstance;
         }
     }
     if (!flag)
     {
         throw ADP.OpenConnectionPropertySet(ADP.ConnectionString, connectionInternal.State);
     }
 }
Exemplo n.º 19
0
 private DBConnectionString(System.Data.Common.DbConnectionOptions connectionOptions, string restrictions, KeyRestrictionBehavior behavior, Hashtable synonyms, bool mustCloneDictionary)
 {
     switch (behavior)
     {
     case KeyRestrictionBehavior.AllowOnly:
     case KeyRestrictionBehavior.PreventUsage:
         this._behavior = behavior;
         this._encryptedUsersConnectionString = connectionOptions.UsersConnectionString(false);
         this._hasPassword = connectionOptions.HasPasswordKeyword;
         this._parsetable  = connectionOptions.Parsetable;
         this._keychain    = connectionOptions.KeyChain;
         if (this._hasPassword && !connectionOptions.HasPersistablePassword)
         {
             if (mustCloneDictionary)
             {
                 this._parsetable = (Hashtable)this._parsetable.Clone();
             }
             if (this._parsetable.ContainsKey("password"))
             {
                 this._parsetable["password"] = "******";
             }
             if (this._parsetable.ContainsKey("pwd"))
             {
                 this._parsetable["pwd"] = "*";
             }
             this._keychain = connectionOptions.ReplacePasswordPwd(out this._encryptedUsersConnectionString, true);
         }
         if (!System.Data.Common.ADP.IsEmpty(restrictions))
         {
             this._restrictionValues = ParseRestrictions(restrictions, synonyms);
             this._restrictions      = restrictions;
         }
         return;
     }
     throw System.Data.Common.ADP.InvalidKeyRestrictionBehavior(behavior);
 }
 protected override DbConnectionOptions CreateConnectionOptions(string connectionString, DbConnectionOptions previous) {
     Debug.Assert(!ADP.IsEmpty(connectionString), "empty connectionString");
     SqlConnectionString result = new SqlConnectionString(connectionString);
     return result;
 }
Exemplo n.º 21
0
        private bool TryGetConnection(DbConnection owningObject, uint waitForMultipleObjectsTimeout, bool allowCreate, bool onlyOneCheckConnection, DbConnectionOptions userOptions, out DbConnectionInternal connection)
        {
            DbConnectionInternal obj = null;
            if (null == obj)
            {
                Interlocked.Increment(ref _waitCount);

                do
                {
                    int waitResult = BOGUS_HANDLE;
                    try
                    {
                        try
                        {
                        }
                        finally
                        {
                            waitResult = WaitHandle.WaitAny(_waitHandles.GetHandles(allowCreate), unchecked((int)waitForMultipleObjectsTimeout));
                        }

                        // From the WaitAny docs: "If more than one object became signaled during
                        // the call, this is the array index of the signaled object with the
                        // smallest index value of all the signaled objects."  This is important
                        // so that the free object signal will be returned before a creation
                        // signal.

                        switch (waitResult)
                        {
                            case WaitHandle.WaitTimeout:
                                Interlocked.Decrement(ref _waitCount);
                                connection = null;
                                return false;

                            case ERROR_HANDLE:
                                // Throw the error that PoolCreateRequest stashed.
                                Interlocked.Decrement(ref _waitCount);
                                throw TryCloneCachedException();

                            case CREATION_HANDLE:

                                try
                                {
                                    obj = UserCreateRequest(owningObject, userOptions);
                                }
                                catch
                                {
                                    if (null == obj)
                                    {
                                        Interlocked.Decrement(ref _waitCount);
                                    }
                                    throw;
                                }
                                finally
                                {
                                    // Ensure that we release this waiter, regardless
                                    // of any exceptions that may be thrown.
                                    if (null != obj)
                                    {
                                        Interlocked.Decrement(ref _waitCount);
                                    }
                                }

                                if (null == obj)
                                {
                                    // If we were not able to create an object, check to see if
                                    // we reached MaxPoolSize.  If so, we will no longer wait on
                                    // the CreationHandle, but instead wait for a free object or
                                    // the timeout.
                                    if (Count >= MaxPoolSize && 0 != MaxPoolSize)
                                    {
                                        if (!ReclaimEmancipatedObjects())
                                        {
                                            // modify handle array not to wait on creation mutex anymore
                                            Debug.Assert(2 == CREATION_HANDLE, "creation handle changed value");
                                            allowCreate = false;
                                        }
                                    }
                                }
                                break;

                            case SEMAPHORE_HANDLE:
                                //
                                //    guaranteed available inventory
                                //
                                Interlocked.Decrement(ref _waitCount);
                                obj = GetFromGeneralPool();

                                if ((obj != null) && (!obj.IsConnectionAlive()))
                                {
                                    DestroyObject(obj);
                                    obj = null;     // Setting to null in case creating a new object fails

                                    if (onlyOneCheckConnection)
                                    {
                                        if (_waitHandles.CreationSemaphore.WaitOne(unchecked((int)waitForMultipleObjectsTimeout)))
                                        {
                                            try
                                            {
                                                obj = UserCreateRequest(owningObject, userOptions);
                                            }
                                            finally
                                            {
                                                _waitHandles.CreationSemaphore.Release(1);
                                            }
                                        }
                                        else
                                        {
                                            // Timeout waiting for creation semaphore - return null
                                            connection = null;
                                            return false;
                                        }
                                    }
                                }
                                break;
                            default:
                                Interlocked.Decrement(ref _waitCount);
                                throw ADP.InternalError(ADP.InternalErrorCode.UnexpectedWaitAnyResult);
                        }
                    }
                    finally
                    {
                        if (CREATION_HANDLE == waitResult)
                        {
                            _waitHandles.CreationSemaphore.Release(1);
                        }
                    }
                } while (null == obj);
            }

            if (null != obj)
            {
                PrepareConnection(owningObject, obj);
            }

            connection = obj;
            return true;
        }
Exemplo n.º 22
0
        private DbConnectionInternal CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
        {
            DbConnectionInternal newObj = null;

            try
            {
                newObj = _connectionFactory.CreatePooledConnection(this, owningObject, _connectionPoolGroup.ConnectionOptions, _connectionPoolGroup.PoolKey, userOptions);
                if (null == newObj)
                {
                    throw ADP.InternalError(ADP.InternalErrorCode.CreateObjectReturnedNull);    // CreateObject succeeded, but null object
                }
                if (!newObj.CanBePooled)
                {
                    throw ADP.InternalError(ADP.InternalErrorCode.NewObjectCannotBePooled);        // CreateObject succeeded, but non-poolable object
                }
                newObj.PrePush(null);

                lock (_objectList)
                {
                    if ((oldConnection != null) && (oldConnection.Pool == this))
                    {
                        _objectList.Remove(oldConnection);
                    }
                    _objectList.Add(newObj);
                    _totalObjects = _objectList.Count;
                }

                // If the old connection belonged to another pool, we need to remove it from that
                if (oldConnection != null)
                {
                    var oldConnectionPool = oldConnection.Pool;
                    if (oldConnectionPool != null && oldConnectionPool != this)
                    {
                        Debug.Assert(oldConnectionPool._state == State.ShuttingDown, "Old connections pool should be shutting down");
                        lock (oldConnectionPool._objectList)
                        {
                            oldConnectionPool._objectList.Remove(oldConnection);
                            oldConnectionPool._totalObjects = oldConnectionPool._objectList.Count;
                        }
                    }
                }

                // Reset the error wait:
                _errorWait = ERROR_WAIT_DEFAULT;
            }
            catch (Exception e)
            {
                if (!ADP.IsCatchableExceptionType(e))
                {
                    throw;
                }
                newObj = null; // set to null, so we do not return bad new object
                // Failed to create instance
                _resError = e;

                // Make sure the timer starts even if ThreadAbort occurs after setting the ErrorEvent.

                // timer allocation has to be done out of CER block
                Timer t = new Timer(new TimerCallback(this.ErrorCallback), null, Timeout.Infinite, Timeout.Infinite);
                bool timerIsNotDisposed;
                try { }
                finally
                {
                    _waitHandles.ErrorEvent.Set();
                    _errorOccurred = true;

                    // Enable the timer.
                    // Note that the timer is created to allow periodic invocation. If ThreadAbort occurs in the middle of ErrorCallback,
                    // the timer will restart. Otherwise, the timer callback (ErrorCallback) destroys the timer after resetting the error to avoid second callback.
                    _errorTimer = t;
                    timerIsNotDisposed = t.Change(_errorWait, _errorWait);
                }

                Debug.Assert(timerIsNotDisposed, "ErrorCallback timer has been disposed");

                if (30000 < _errorWait)
                {
                    _errorWait = 60000;
                }
                else
                {
                    _errorWait *= 2;
                }
                throw;
            }
            return newObj;
        }
Exemplo n.º 23
0
        private DbConnectionInternal UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection = null)
        {
            // called by user when they were not able to obtain a free object but
            // instead obtained creation mutex

            DbConnectionInternal obj = null;
            if (ErrorOccurred)
            {
                throw TryCloneCachedException();
            }
            else
            {
                if ((oldConnection != null) || (Count < MaxPoolSize) || (0 == MaxPoolSize))
                {
                    // If we have an odd number of total objects, reclaim any dead objects.
                    // If we did not find any objects to reclaim, create a new one.
                    if ((oldConnection != null) || (Count & 0x1) == 0x1 || !ReclaimEmancipatedObjects())
                        obj = CreateObject(owningObject, userOptions, oldConnection);
                }
                return obj;
            }
        }
 internal override bool TryReplaceConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource<DbConnectionInternal> retry, DbConnectionOptions userOptions) {
     return base.TryOpenConnectionInternal(outerConnection, connectionFactory, retry, userOptions);
 }
 internal virtual System.Data.ProviderBase.DbConnectionPoolProviderInfo CreateConnectionPoolProviderInfo(System.Data.Common.DbConnectionOptions connectionOptions)
 {
     return(null);
 }
 protected abstract System.Data.Common.DbConnectionOptions CreateConnectionOptions(string connectionString, System.Data.Common.DbConnectionOptions previous);
Exemplo n.º 27
0
        protected override System.Data.ProviderBase.DbConnectionPoolGroupOptions CreateConnectionPoolGroupOptions(System.Data.Common.DbConnectionOptions connectionOptions)
        {
            OracleConnectionString str = (OracleConnectionString)connectionOptions;

            System.Data.ProviderBase.DbConnectionPoolGroupOptions options = null;
            if (str.Pooling)
            {
                options = new System.Data.ProviderBase.DbConnectionPoolGroupOptions(str.IntegratedSecurity, str.MinPoolSize, str.MaxPoolSize, 0x7530, str.LoadBalanceTimeout, str.Enlist, false);
            }
            return(options);
        }
Exemplo n.º 28
0
 protected override System.Data.Common.DbConnectionOptions CreateConnectionOptions(string connectionOptions, System.Data.Common.DbConnectionOptions previous)
 {
     return(new OracleConnectionString(connectionOptions));
 }
Exemplo n.º 29
0
 protected override System.Data.ProviderBase.DbConnectionInternal CreateConnection(System.Data.Common.DbConnectionOptions options, object poolGroupProviderInfo, System.Data.ProviderBase.DbConnectionPool pool, DbConnection owningObject)
 {
     return(new OracleInternalConnection(options as OracleConnectionString));
 }
Exemplo n.º 30
0
 public static void AppendKeyValuePair(StringBuilder builder, string keyword, string?value, bool useOdbcRules)
 {
     DbConnectionOptions.AppendKeyValuePairBuilder(builder, keyword, value, useOdbcRules);
 }
 internal DBConnectionString(DbConnectionOptions connectionOptions)
     : this(connectionOptions, (string)null, KeyRestrictionBehavior.AllowOnly, (Hashtable)null, true)
 {
     // used by DBDataPermission to convert from DbConnectionOptions to DBConnectionString
     // since backward compatability requires Everett level classes
 }
        override protected DbConnectionPoolGroupOptions CreateConnectionPoolGroupOptions( DbConnectionOptions connectionOptions ) {
            SqlConnectionString opt = (SqlConnectionString)connectionOptions;

            DbConnectionPoolGroupOptions poolingOptions = null;

            if (!opt.ContextConnection && opt.Pooling) {    // never pool context connections.
                int connectionTimeout = opt.ConnectTimeout;

                if ((0 < connectionTimeout) && (connectionTimeout < Int32.MaxValue/1000))
                    connectionTimeout *= 1000;
                else if (connectionTimeout >= Int32.MaxValue/1000)
                    connectionTimeout = Int32.MaxValue;

                poolingOptions = new DbConnectionPoolGroupOptions(
                                                    opt.IntegratedSecurity,
                                                    opt.MinPoolSize,
                                                    opt.MaxPoolSize,
                                                    connectionTimeout,
                                                    opt.LoadBalanceTimeout,
                                                    opt.Enlist);
            }
            return poolingOptions;
        }
Exemplo n.º 33
0
 public static void AppendKeyValuePair(StringBuilder builder, string keyword, string value)
 {
     DbConnectionOptions.AppendKeyValuePairBuilder(builder, keyword, value, false);
 }
 override protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) {
     return CreateConnection(options, poolKey, poolGroupProviderInfo, pool, owningConnection, userOptions: null);
 }
 protected abstract System.Data.ProviderBase.DbConnectionPoolGroupOptions CreateConnectionPoolGroupOptions(System.Data.Common.DbConnectionOptions options);
		protected void SetConnectionString (DbConnectionOptions constr)
		{
			throw new NotImplementedException ();
		}
Exemplo n.º 37
0
 internal DBConnectionString(System.Data.Common.DbConnectionOptions connectionOptions) : this(connectionOptions, null, KeyRestrictionBehavior.AllowOnly, null, true)
 {
 }
Exemplo n.º 38
0
 internal DBConnectionString(DbConnectionOptions connectionOptions) : this(connectionOptions, null, KeyRestrictionBehavior.AllowOnly, null, true)
 {
 }
Exemplo n.º 39
0
 protected DbConnectionOptions(DbConnectionOptions connectionOptions)
 { // Clone used by SqlConnectionString
     _usersConnectionString = connectionOptions._usersConnectionString;
     HasPasswordKeyword = connectionOptions.HasPasswordKeyword;
     _parsetable = connectionOptions._parsetable;
     KeyChain = connectionOptions.KeyChain;
 }
Exemplo n.º 40
0
 abstract protected DbConnectionPoolGroupOptions CreateConnectionPoolGroupOptions(DbConnectionOptions options);
Exemplo n.º 41
0
 public PendingGetConnection(long dueTime, DbConnection owner, TaskCompletionSource<DbConnectionInternal> completion, DbConnectionOptions userOptions)
 {
     DueTime = dueTime;
     Owner = owner;
     Completion = completion;
 }
Exemplo n.º 42
0
 internal virtual DbConnectionPoolProviderInfo CreateConnectionPoolProviderInfo(DbConnectionOptions connectionOptions)
 {
     return null;
 }
Exemplo n.º 43
0
        internal bool TryGetConnection(DbConnection owningObject, TaskCompletionSource<DbConnectionInternal> retry, DbConnectionOptions userOptions, out DbConnectionInternal connection)
        {
            uint waitForMultipleObjectsTimeout = 0;
            bool allowCreate = false;

            if (retry == null)
            {
                waitForMultipleObjectsTimeout = (uint)CreationTimeout;

                // Set the wait timeout to INFINITE (-1) if the SQL connection timeout is 0 (== infinite)
                if (waitForMultipleObjectsTimeout == 0)
                    waitForMultipleObjectsTimeout = unchecked((uint)Timeout.Infinite);

                allowCreate = true;
            }

            if (_state != State.Running)
            {
                connection = null;
                return true;
            }

            bool onlyOneCheckConnection = true;
            if (TryGetConnection(owningObject, waitForMultipleObjectsTimeout, allowCreate, onlyOneCheckConnection, userOptions, out connection))
            {
                return true;
            }
            else if (retry == null)
            {
                // timed out on a sync call
                return true;
            }

            var pendingGetConnection =
                new PendingGetConnection(
                    CreationTimeout == 0 ? Timeout.Infinite : ADP.TimerCurrent() + ADP.TimerFromSeconds(CreationTimeout / 1000),
                    owningObject,
                    retry,
                    userOptions);
            _pendingOpens.Enqueue(pendingGetConnection);

            // it is better to StartNew too many times than not enough
            if (_pendingOpensWaiting == 0)
            {
                Thread waitOpenThread = new Thread(WaitForPendingOpen);
                waitOpenThread.IsBackground = true;
                waitOpenThread.Start();
            }

            connection = null;
            return false;
        }
Exemplo n.º 44
0
        internal DbConnectionInternal CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
        {
            Debug.Assert(null != owningConnection, "null owningConnection?");
            Debug.Assert(null != poolGroup, "null poolGroup?");

            DbConnectionOptions connectionOptions = poolGroup.ConnectionOptions;
            DbConnectionPoolGroupProviderInfo poolGroupProviderInfo = poolGroup.ProviderInfo;
            DbConnectionPoolKey poolKey = poolGroup.PoolKey;

            DbConnectionInternal newConnection = CreateConnection(connectionOptions, poolKey, poolGroupProviderInfo, null, owningConnection, userOptions);
            if (null != newConnection)
            {
                newConnection.MakeNonPooledObject(owningConnection);
            }
            return newConnection;
        }
Exemplo n.º 45
0
        /// <summary>
        /// Creates a new connection to replace an existing connection
        /// </summary>
        /// <param name="owningObject">Outer connection that currently owns <paramref name="oldConnection"/></param>
        /// <param name="userOptions">Options used to create the new connection</param>
        /// <param name="oldConnection">Inner connection that will be replaced</param>
        /// <returns>A new inner connection that is attached to the <paramref name="owningObject"/></returns>
        internal DbConnectionInternal ReplaceConnection(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
        {
            DbConnectionInternal newConnection = UserCreateRequest(owningObject, userOptions, oldConnection);

            if (newConnection != null)
            {
                PrepareConnection(owningObject, newConnection);
                oldConnection.PrepareForReplaceConnection();
                oldConnection.DeactivateConnection();
                oldConnection.Dispose();
            }

            return newConnection;
        }
 internal System.Data.ProviderBase.DbConnectionPoolGroup GetConnectionPoolGroup(string connectionString, System.Data.ProviderBase.DbConnectionPoolGroupOptions poolOptions, ref System.Data.Common.DbConnectionOptions userConnectionOptions)
 {
     System.Data.ProviderBase.DbConnectionPoolGroup group;
     if (System.Data.Common.ADP.IsEmpty(connectionString))
     {
         return(null);
     }
     if (!this._connectionPoolGroups.TryGetValue(connectionString, out group) || (group.IsDisabled && (group.PoolGroupOptions != null)))
     {
         System.Data.Common.DbConnectionOptions options = this.CreateConnectionOptions(connectionString, userConnectionOptions);
         if (options == null)
         {
             throw System.Data.Common.ADP.InternalConnectionError(System.Data.Common.ADP.ConnectionError.ConnectionOptionsMissing);
         }
         string str = connectionString;
         if (userConnectionOptions == null)
         {
             userConnectionOptions = options;
             str = options.Expand();
             if (str != connectionString)
             {
                 return(this.GetConnectionPoolGroup(str, null, ref userConnectionOptions));
             }
         }
         if ((poolOptions == null) && System.Data.Common.ADP.IsWindowsNT)
         {
             if (group != null)
             {
                 poolOptions = group.PoolGroupOptions;
             }
             else
             {
                 poolOptions = this.CreateConnectionPoolGroupOptions(options);
             }
         }
         System.Data.ProviderBase.DbConnectionPoolGroup group2 = new System.Data.ProviderBase.DbConnectionPoolGroup(options, poolOptions)
         {
             ProviderInfo = this.CreateConnectionPoolGroupProviderInfo(options)
         };
         lock (this)
         {
             Dictionary <string, System.Data.ProviderBase.DbConnectionPoolGroup> dictionary = this._connectionPoolGroups;
             if (!dictionary.TryGetValue(str, out group))
             {
                 Dictionary <string, System.Data.ProviderBase.DbConnectionPoolGroup> dictionary2 = new Dictionary <string, System.Data.ProviderBase.DbConnectionPoolGroup>(1 + dictionary.Count);
                 foreach (KeyValuePair <string, System.Data.ProviderBase.DbConnectionPoolGroup> pair in dictionary)
                 {
                     dictionary2.Add(pair.Key, pair.Value);
                 }
                 dictionary2.Add(str, group2);
                 this.PerformanceCounters.NumberOfActiveConnectionPoolGroups.Increment();
                 group = group2;
                 this._connectionPoolGroups = dictionary2;
             }
             return(group);
         }
     }
     if (userConnectionOptions == null)
     {
         userConnectionOptions = group.ConnectionOptions;
     }
     return(group);
 }
        override internal DbConnectionPoolProviderInfo CreateConnectionPoolProviderInfo(DbConnectionOptions connectionOptions){
            DbConnectionPoolProviderInfo providerInfo = null;

            if (((SqlConnectionString) connectionOptions).UserInstance) {
                providerInfo = new SqlConnectionPoolProviderInfo();
            }

            return providerInfo;
        }
 protected abstract System.Data.ProviderBase.DbConnectionInternal CreateConnection(System.Data.Common.DbConnectionOptions options, object poolGroupProviderInfo, System.Data.ProviderBase.DbConnectionPool pool, DbConnection owningConnection);
 override internal DbConnectionPoolGroupProviderInfo CreateConnectionPoolGroupProviderInfo (DbConnectionOptions connectionOptions) {
     return new SqlConnectionPoolGroupProviderInfo((SqlConnectionString)connectionOptions);
 }
Exemplo n.º 50
0
 protected internal DbConnectionOptions(DbConnectionOptions connectionOptions)
 {
     options = connectionOptions.options;
 }
        override protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) {
            SqlConnectionString opt = (SqlConnectionString)options;
            SqlConnectionPoolKey key = (SqlConnectionPoolKey) poolKey;
            SqlInternalConnection result = null;
            SessionData recoverySessionData = null;

            SqlConnectionString userOpt = null;
            if (userOptions != null) {
                userOpt = (SqlConnectionString)userOptions;
            }
            else if (owningConnection != null) {
                userOpt = (SqlConnectionString)(((SqlConnection)owningConnection).UserConnectionOptions);                
            }

            if (owningConnection != null) {
                recoverySessionData = ((SqlConnection)owningConnection)._recoverySessionData;
            }

            if (opt.ContextConnection) {
                result = GetContextConnection(opt, poolGroupProviderInfo);
            }
            else {
                bool redirectedUserInstance       = false;
                DbConnectionPoolIdentity identity = null;

                // Pass DbConnectionPoolIdentity to SqlInternalConnectionTds if using integrated security.
                // Used by notifications.
                if (opt.IntegratedSecurity) {
                    if (pool != null) {
                        identity = pool.Identity;
                    }
                    else {
                        identity = DbConnectionPoolIdentity.GetCurrent();
                    }
                }

                // FOLLOWING IF BLOCK IS ENTIRELY FOR SSE USER INSTANCES
                // If "user instance=true" is in the connection string, we're using SSE user instances
                if (opt.UserInstance) {
                    // opt.DataSource is used to create the SSE connection
                    redirectedUserInstance = true;
                    string instanceName;

                    if ( (null == pool) || 
                         (null != pool && pool.Count <= 0) ) { // Non-pooled or pooled and no connections in the pool.

                        SqlInternalConnectionTds sseConnection = null;
                        try {
                            // What about a failure - throw?  YES!
                            // 



                            SqlConnectionString sseopt = new SqlConnectionString(opt, opt.DataSource, true /* user instance=true */, false /* set Enlist = false */);
                            sseConnection = new SqlInternalConnectionTds(identity, sseopt, key.Credential, null, "", null, false);
                            // NOTE: Retrieve <UserInstanceName> here. This user instance name will be used below to connect to the Sql Express User Instance.
                            instanceName = sseConnection.InstanceName;

                            if (!instanceName.StartsWith("\\\\.\\", StringComparison.Ordinal)) {
                                throw SQL.NonLocalSSEInstance();
                            }

                            if (null != pool) { // Pooled connection - cache result
                                SqlConnectionPoolProviderInfo providerInfo = (SqlConnectionPoolProviderInfo) pool.ProviderInfo;
                                // No lock since we are already in creation mutex
                                providerInfo.InstanceName = instanceName;
                            }
                        }
                        finally {
                            if (null != sseConnection) {
                                sseConnection.Dispose();
                            }
                        }
                    }
                    else { // Cached info from pool.
                        SqlConnectionPoolProviderInfo providerInfo = (SqlConnectionPoolProviderInfo) pool.ProviderInfo;
                        // No lock since we are already in creation mutex
                        instanceName = providerInfo.InstanceName;
                    }

                    // NOTE: Here connection option opt is cloned to set 'instanceName=<UserInstanceName>' that was
                    //       retrieved from the previous SSE connection. For this UserInstance connection 'Enlist=True'.
                    // options immutable - stored in global hash - don't modify
                    opt = new SqlConnectionString(opt, instanceName, false /* user instance=false */, null /* do not modify the Enlist value */);
                    poolGroupProviderInfo = null; // null so we do not pass to constructor below...
                }
                result = new SqlInternalConnectionTds(identity, opt, key.Credential, poolGroupProviderInfo, "", null, redirectedUserInstance, userOpt, recoverySessionData);            
            }
            return result;
        }
Exemplo n.º 52
0
 abstract protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection);
		protected DBDataPermission (DbConnectionOptions connectionOptions)
			: this (PermissionState.None)
		{
			// ignore null (i.e. no ArgumentNullException)
			if (connectionOptions != null) {
				throw new NotImplementedException ();
			}
		}
Exemplo n.º 54
0
 abstract protected DbConnectionOptions CreateConnectionOptions(string connectionString, DbConnectionOptions previous);