Esempio n. 1
0
 public OracleConnectionPool(OracleConnectionPoolManager manager, OracleConnectionInfo info, int minPoolSize, int maxPoolSize)
 {
     this.info    = info;
     this.manager = manager;
     initialized  = false;
     PoolMinSize  = minPoolSize;
     PoolMaxSize  = maxPoolSize;
 }
		public OracleConnectionPool (OracleConnectionPoolManager manager, OracleConnectionInfo info, int minPoolSize, int maxPoolSize) 
		{
			this.info = info;
			this.manager = manager;
			initialized = false;
			PoolMinSize = minPoolSize;
			PoolMaxSize = maxPoolSize;
		}
        /// <include file='doc\OracleConnection.uex' path='docs/doc[@for="OracleConnection.Open"]/*' />
        private void OpenInternal(OracleConnectionString parsedConnectionString, object transact)
        {
            bool isInTransaction;

            try
            {
                try
                {
                    if (null == parsedConnectionString)
                    {
                        throw ADP.NoConnectionString();
                    }

                    _state = ConnectionState.Connecting;

                    if (false == parsedConnectionString.Pooling || null != transact)
                    {
                        _internalConnection = new OracleInternalConnection(parsedConnectionString, transact);
                    }
                    else
                    {
#if ALLOWTRACING
                        if (ADP._traceObjectPoolActivity)
                        {
                            if (ContextUtil.IsInTransaction)
                            {
                                Debug.WriteLine("Getting Pooled Connection For TransactionId=" + ContextUtil.TransactionId + " ContextId=" + ContextUtil.ContextId);
                            }
                            else
                            {
                                Debug.WriteLine("Getting Pooled Connection without Transaction Context");
                            }
                        }
#endif //ALLOWTRACING
                        _internalConnection = OracleConnectionPoolManager.GetPooledConnection(
                            parsedConnectionString.EncryptedActualConnectionString,
                            parsedConnectionString,
                            this,
                            out isInTransaction
                            );

#if USEORAMTS
                        // Note that we'll only have a non-null transact object when we are manually
                        // enlisted -- automatically enlisted connections take a different path.
                        _internalConnection.ManualEnlistedTransaction = (ITransaction)transact;
#endif //USEORAMTS
                    }

                    _hidePassword           = true;
                    _state                  = ConnectionState.Open;
                    _parsedConnectionString = parsedConnectionString;

                    if (UnicodeEnabled)
                    {
                        _encodingDatabase = System.Text.Encoding.Unicode;                               // for environments initialized in UTF16 mode, we can use straight Unicode
                    }
                    else if (ServerVersionAtLeastOracle8i)
                    {
                        _encodingDatabase = new OracleEncoding(this);                                           // for Oracle8i or greater we'll use Oracle's conversion routines.
                    }
                    else
                    {
                        _encodingDatabase = System.Text.Encoding.Default;                               // anything prior to Oracle8i doesn't work with Oracle's conversion routines.
                    }
                    _encodingNational = System.Text.Encoding.Unicode;                                   // we use Unicode for the NCHAR/NVARCHAR/NCLOB and let Oracle perform the conversion automatically.
                }
                finally
                {
                    if (ConnectionState.Open != _state)
                    {
                        Cleanup(true, true);
                    }
                }
            }
            catch // Prevent exception filters from running in our space
            {
                throw;
            }
        }
        internal void Cleanup(bool disposing, bool silent)
        {
            //	Cleanup the connection as best we can, releasing as many objects
            //	as we can.  We use this when we fail to connect completely, when
            //	we are closing the connection, and when we're disposing of this
            //	object.

            bool fireEvent = false;

            _serverTimeZoneAdjustment = TimeSpan.MinValue;

            // Increment the close counter so the child objects can know when their
            // connection is toast (or being re-used)
            Interlocked.Increment(ref _closeCount);

            // If we're not disposing, it's because we went out of scope, and we're
            // being garbage collected.  We shouldn't touch any managed objects
            // or bad things can happen.
            if (disposing)
            {
                // We need to "dispose" of the internal connection object, either
                // by returning it to the pool (if it came from one) or by closing it
                // outright.
                if (null != _internalConnection)
                {
                    if (null == _internalConnection.Pool)
                    {
                        // We just close the connection; there is no need to rollback
                        // here because Oracle will do it for us.
                        _internalConnection.Close();
                    }
                    else
                    {
                        // Before we return the connection to the pool, we rollback any
                        // active transaction that may have been created.  Note that we
                        // don't bother with distributed transactions because we don't
                        // want to them back (it's handled by the TM).  We also don't
                        // worry about implicit transactions (like "select...for update")
                        // because we don't want to take the performance hit of the server
                        // round-trip when it isn't very likely.
                        if (TransactionState.LocalStarted == TransState)
                        {
                            // On the off chance that we have some failure during rollback
                            // we just eat it and make sure that the connection is doomed.
                            try
                            {
                                Rollback();
                            }
                            catch (Exception e)
                            {
                                ADP.TraceException(e);
                                _internalConnection.DoomThisConnection();
                            }
                        }
                        OracleConnectionPoolManager.ReturnPooledConnection(_internalConnection, this);
                    }

                    _internalConnection = null;
                }

                if (null != _scratchBuffer)
                {
                    _scratchBuffer.Dispose();
                    _scratchBuffer = null;
                }

                // Mark this connection as closed
                if (_state != ConnectionState.Closed)
                {
                    _state    = ConnectionState.Closed;
                    fireEvent = true;
                }

                _encodingDatabase = null;
                _encodingNational = null;

                if (fireEvent && !silent)
                {
                    OnStateChange(ConnectionState.Open, ConnectionState.Closed);
                }
            }
        }