Пример #1
0
		/*
		** Name: Open
		**
		** History:
		**	27-Aug-02 (thoda04)
		**	    Created.
		*/

		/// <summary>
		/// Open the database connection and set the ConnectionState property.
		/// </summary>
		public override void Open()
		{
			System.EnterpriseServices.ITransaction transaction;

			if (_state == ConnectionState.Open)
				throw new InvalidOperationException("The connection is already open.");

			if (config == null)  // if no connection string then bad news
				throw new InvalidOperationException("Host specification missing");

			string host = DataSource;
			if (host == null)
				throw new InvalidOperationException("Host specification missing");

			// if not "servername:port" format then
			// get the port number from keyword=value NameValueCollection
			if (host.IndexOf(":") == -1)
			{
				string port = config.Get(DrvConst.DRV_PROP_PORT);
				if (port == null || port.Length == 0)
					port = "II7"; // no "Port=" then default to "II7"
				host += ":" + port.ToString();  // add ":portid" to host
			}

			advanConnect = AdvanConnectionPoolManager.Get(
				ConnectionString, this, host, config, null, ConnectionTimeout);

			// advanConnect internal connection object may be later used by
			// two threads: the application thread and the MSDTC proxy thread.
			// The advanConnect usage count will block release of the internal
			// connection advanConnect object back into the connection pool
			// until each is finished and calls
			// advanConnect.CloseOrPutBackIntoConnectionPool() method.
			// See DTCEnlistment.Enlist() method for MSDTC proxy claim stake.
			advanConnect.ReferenceCountIncrement();  // application thread stakes it claim

			ConnectionState oldState = _state;
			_state = ConnectionState.Open;

			// Raise the connection state change event
			FireStateChange(oldState, _state);  // old, new

			string persistSecurityInfo = config.Get(DrvConst.DRV_PROP_PERSISTSEC);
			if (persistSecurityInfo == null  ||
				(ToInvariantLower(persistSecurityInfo) != "true"  &&
				 ToInvariantLower(persistSecurityInfo) != "yes"))
				_connectionString = _connectionStringSanitized;

			transaction = EnlistDistributedTransactionIsNeeded();

			if (transaction != null)
				EnlistDistributedTransaction(transaction, false);  // implicit enlistment
		}
Пример #2
0
		/*
		** Name: ReleaseObjectPool
		**
		** Description:
		**	Release the connection pool when last connection is closed.
		**
		** History:
		**	23-Dec-03 (thoda04)
		**	    Created.
		*/

		/// <summary>
		/// Release the connection pool when last connection is closed.
		/// </summary>
		public static void ReleaseObjectPool()
		{
			AdvanConnectionPoolManager.ReleasePool();
		}