Example #1
0
		/// <summary>
		/// Begin a local database transaction with a specified isolation level.
		/// </summary>
		/// <param name="isoLevel"></param>
		/// <returns>An IngresTransaction object.</returns>
		public new  IngresTransaction BeginTransaction(IsolationLevel isoLevel)
		{
			if (State != ConnectionState.Open)  // conn must be already open
				throw new InvalidOperationException(
					"The connection is not open.");

			// Check that not already enlisted in a DistributedTransaction.
			if (this.DTCenlistment != null)
				throw new InvalidOperationException(
					"The connection has already enlisted " +
					"in a distributed transaction.");

			// Check that not already in a local transaction from a BeginTransaction.
			if (this.Transaction != null)
				throw new InvalidOperationException(
					"The connection has already begun a local transaction.");

			// attempt to get an IngresTransaction with the specified isoLevel
			IngresTransaction tx = new IngresTransaction(this, isoLevel);

			// make sure we can turn off autocommit before setting Transaction
			advanConnect.setAutoCommit(false);   // turn autocommit off

			Transaction = tx;  // all's well, set the Transaction property
			return Transaction;
		}
Example #2
0
		/*
		** Name: Close
		**
		** History:
		**	27-Aug-02 (thoda04)
		**	    Created.
		*/

		/// <summary>
		/// Close the database connection or release it back into connection pool.
		/// </summary>
		public override void Close()
		{
			if (_state == ConnectionState.Closed)
				return;

			if (ActiveDataReader != null)  // Close any open DataReader
				ActiveDataReader.Close();

			if (advanConnect != null)
			{
				if (Transaction != null  &&
					Transaction.HasAlreadyBeenCommittedOrRolledBack == false)
				{
					Transaction.Rollback();
					Transaction = null;
				}

				// put the advantage connection back into pool or close it
				advanConnect.CloseOrPutBackIntoConnectionPool();
				advanConnect = null;
			}

			ConnectionState oldState = _state;
			_state = ConnectionState.Closed;
			_serverVersion = null;  // ServerVersion property is now invalid

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

		}
        /// <summary>
        /// Initializes a new instance of the IngresRoleProviderHandler class.
        /// </summary>
        /// <param name="conn">The Ingres connection to use.</param>
        /// <param name="tran">The Ingres transaction to use.</param>
        /// <param name="config">The configuration settings to use.</param>
        /// <param name="provider">The Ingres Role Provider facade to use.</param>
        internal IngresRoleProviderHandler(IngresConnection conn, IngresTransaction tran, IngresRoleProviderConfiguration config, IngresRoleProvider provider)
        {
            if (conn == null || tran == null)
            {
                throw new Exception();
            }

            this.tran = tran;
            this.conn = conn;

            this.config = config;
            this.provider = provider;
        }
Example #4
0
		/// <summary>
		/// Enlist the connection into the distributed transaction.
		/// </summary>
		/// <param name="transaction"></param>
		/// <param name="isExplicitTransaction">User transaction if true;
		/// implicit Contextutil.Transaction or System.Transactions if false.</param>
		private void EnlistDistributedTransaction(
			System.EnterpriseServices.ITransaction transaction,
			bool                                   isExplicitTransaction)
		{
			// Check that a BeginTransaction has not already been issued.
			if (Transaction != null)
				if (Transaction.HasAlreadyBeenCommittedOrRolledBack)
					Transaction = null;
				else
					throw new InvalidOperationException(
						"The connection has already begun a transaction " +
						"using BeginTransaction.");

			// The connection must be open before 
			// calling EnlistDistributedTransaction.
			if (State != ConnectionState.Open)
				throw new InvalidOperationException(
					"The connection must be open before " +
					"calling EnlistDistributedTransaction.");

			try
			{
				// If an old DTCEnlistment exists then make sure its closed
				if (this.DTCenlistment != null)
				{
					this.DTCenlistment.Delist();
					this.DTCenlistment = null;
				}

				advanConnect.setAutoCommit(false);   // turn autocommit off

				DTCEnlistment DTCenlistment = new DTCEnlistment();
				DTCenlistment.Enlist(
					this.advanConnect, transaction, config);

				this.DTCenlistment = DTCenlistment;  // a good MSDTC enlistment in the tx
			}
			catch( SqlEx ex )
			{
				throw ex.createProviderException();
			}
		}
Example #5
0
        private void InitTransaction()
        {
            switch (DatabaseManager.DatabaseConnectionType.ToLower())
            {
                case "firebird":
                    CommandFireBird = Client.CreateNewCommandFireBird();
                    _transactionfirebird = Client.GetTransactionFireBird();
                    CommandFireBird.Transaction = _transactionfirebird;
                    CommandFireBird.Connection = _transactionfirebird.Connection;
                    break;
                case "ingres":
                case "ingress":
                    CommandIngress = Client.CreateNewCommandIngress();
                    _transactioningress = Client.GetTransactionIngress();
                    CommandIngress.Transaction = _transactioningress;
                    break;
                case "pgsql":
                    CommandPgSql = Client.CreateNewCommandPgSql();
                    _transactionpgsql = Client.GetTransactionPgSql();
                    CommandPgSql.Transaction = _transactionpgsql;
                    CommandPgSql.Connection = _transactionpgsql.Connection;
                    break;
                default:
                    CommandMySql = Client.CreateNewCommandMySql();
                    _transactionmysql = Client.GetTransactionMySql();
                    CommandMySql.Transaction = _transactionmysql;
                    CommandMySql.Connection = _transactionmysql.Connection;
                    break;
            }

            _finishedTransaction = false;
        }
 /// <summary>
 /// Gets a handler for the Ingres membership provider.
 /// </summary>
 /// <param name="conn">The Ingres connection.</param>
 /// <param name="tran">The Ingres transaction to use.</param>
 /// <returns>The handler</returns>
 private IngresMembershipProviderHandler GetHandler(IngresConnection conn, IngresTransaction tran)
 {
     IngresMembershipProviderHandler handler = new IngresMembershipProviderHandler(conn, tran, this.config, this);
     return handler;
 }
Example #7
0
	/// <summary>
	/// Create a new instance of IngresCommand with specified SQL text string,
	/// IngresConnection, and Transaction objects.
	/// </summary>
	/// <param name="cmdText">SQL text string.</param>
	/// <param name="connection">
	/// IngresConnection to be associated with this command.</param>
	/// <param name="transaction">
	/// IngresTransaction to be associated with this command.</param>
	public IngresCommand(string cmdText, IngresConnection  connection,
				IngresTransaction transaction)
		{
		InitializeComponent();
		_commandText = cmdText;
		_connection  = connection;
		_transaction = transaction;
	}
Example #8
0
		/// <summary>
		/// Release allocated resources of the Command and base Component.
		/// </summary>
		/// <param name="disposing">
		/// true if object is being explicitly disposed of, not finalized.
		/// false if method is called by runtime from inside the finalizer.
		/// </param>
	protected override void Dispose(bool disposing)
	{
		/*if disposing == true  Object is being explicitly disposed of, not finalized
		  if disposing == false then method called by runtime from inside the
									finalizer and we should not reference other 
									objects. */
		lock(this)
		{
			try
			{
				if (disposing)
				{
					Connection = null;
					_transaction = null;
					_commandText = null;
					_parameters = null;
					advanStmt   = null;
				}
			}
			finally
			{
				base.Dispose(disposing);  // let component base do its cleanup
			}
		}
	}
Example #9
0
        /// <summary>
        /// Enlist the connection into the distributed transaction.
        /// </summary>
        /// <param name="transaction"></param>
        /// <param name="isExplicitTransaction">User transaction if true;
        /// implicit Contextutil.Transaction or System.Transactions if false.</param>
        private void EnlistDistributedTransaction(
			System.EnterpriseServices.ITransaction transaction,
			bool                                   isExplicitTransaction)
        {
            // Check that a BeginTransaction has not already been issued.
            if (Transaction != null)
                if (Transaction.HasAlreadyBeenCommittedOrRolledBack)
                    Transaction = null;
                else
                    throw new InvalidOperationException(
                        "The connection has already begun a transaction " +
                        "using BeginTransaction.");

            // The connection must be open before
            // calling EnlistDistributedTransaction.
            if (State != ConnectionState.Open)
                throw new InvalidOperationException(
                    "The connection must be open before " +
                    "calling EnlistDistributedTransaction.");

            try
            {
                // If an old DTCEnlistment exists then make sure its closed
                if (this.DTCenlistment != null)
                {
                    this.DTCenlistment.Delist();
                    this.DTCenlistment = null;
                }

                advanConnect.setAutoCommit(false);   // turn autocommit off

                DTCEnlistment DTCenlistment = new DTCEnlistment();
                DTCenlistment.Enlist(
                    this.advanConnect, transaction, config);

                this.DTCenlistment = DTCenlistment;  // a good MSDTC enlistment in the tx
            }
            catch( SqlEx ex )
            {
                throw ex.createProviderException();
            }
        }
Example #10
0
        /*
        ** Name: Close
        **
        ** History:
        **	27-Aug-02 (thoda04)
        **	    Created.
        */
        /// <summary>
        /// Close the database connection or release it back into connection pool.
        /// </summary>
        public override void Close()
        {
            if (_state == ConnectionState.Closed)
                return;

            if (ActiveDataReader != null)  // Close any open DataReader
                ActiveDataReader.Close();

            if (advanConnect != null)
            {
                if (Transaction != null  &&
                    Transaction.HasAlreadyBeenCommittedOrRolledBack == false)
                {
                    Transaction.Rollback();
                    Transaction = null;
                }

                // put the advantage connection back into pool or close it
                advanConnect.CloseOrPutBackIntoConnectionPool();
                advanConnect = null;
            }

            ConnectionState oldState = _state;
            _state = ConnectionState.Closed;
            _serverVersion = null;  // ServerVersion property is now invalid

            // Raise the connection state change
            FireStateChange(oldState, _state);  // old, new
        }
Example #11
0
        /// <summary>
        /// Begin a local database transaction with a specified isolation level.
        /// </summary>
        /// <param name="isoLevel"></param>
        /// <returns>An IngresTransaction object.</returns>
        public new IngresTransaction BeginTransaction(IsolationLevel isoLevel)
        {
            if (State != ConnectionState.Open)  // conn must be already open
                throw new InvalidOperationException(
                    "The connection is not open.");

            // Check that not already enlisted in a DistributedTransaction.
            if (this.DTCenlistment != null)
                throw new InvalidOperationException(
                    "The connection has already enlisted " +
                    "in a distributed transaction.");

            // Check that not already in a local transaction from a BeginTransaction.
            if (this.Transaction != null)
                throw new InvalidOperationException(
                    "The connection has already begun a local transaction.");

            // attempt to get an IngresTransaction with the specified isoLevel
            IngresTransaction tx = new IngresTransaction(this, isoLevel);

            // make sure we can turn off autocommit before setting Transaction
            advanConnect.setAutoCommit(false);   // turn autocommit off

            Transaction = tx;  // all's well, set the Transaction property
            return Transaction;
        }
        /// <summary>
        /// Creates a role in the database.
        /// </summary>
        /// <param name="roleName">The rolename to create.</param>
        /// <param name="roleid">The role id.</param>
        /// <param name="conn">The Ingres connection to use.</param>
        /// <param name="tran">The Ingres transaction to use.</param>
        private void CreateRole(string roleName, out string roleid, IngresConnection conn, IngresTransaction tran)
        {
            // Validate the roleName
            ValidationUtil.CheckParameterIsOK(ref roleName, true, true, true, 256, "roleName");

            // Ensure that the proposed roleName does not already exist
            if (this.RoleExists(roleName))
            {
                throw new ProviderException(string.Format(Messages.RoleAlreadyExists, roleName));
            }

            string sql = @"
                            INSERT INTO aspnet_Roles
                               (ApplicationId,
                                RoleId,
                                RoleName,
                                LoweredRoleName,
                                Description)
                            VALUES
                               (?,
                                ?,
                                ?,
                                ?,
                                NULL)
                         ";

            // Create the command with the current connection and enrol in the transaction
            IngresCommand cmd = new IngresCommand(sql, this.conn);
            cmd.Transaction = this.tran;
            cmd.CommandTimeout = this.config.CommandTimeout;

            // Generate a new role Id - this will be the sent out
            roleid = Guid.NewGuid().ToString().ToLower();

            // Add the required parameters
            cmd.Parameters.Add("ApplicationId", DbType.String).Value = this.ApplicationId;
            cmd.Parameters.Add("RoleId",          DbType.String).Value = roleid;
            cmd.Parameters.Add("RoleName",        DbType.String).Value = roleName;
            cmd.Parameters.Add("LoweredRoleName", DbType.String).Value = roleName.ToLower();

            // Execute the query
            int rows = cmd.ExecuteNonQuery();

            // Validate that the query affected the correct numbber of rows.
            if (rows != 1)
            {
                throw new ProviderException(string.Format(Messages.UnknownError));
            }
        }
        /// <summary>
        /// Gets the Id for the current application.
        /// </summary>
        /// <param name="conn">The Ingres connection to use.</param>
        /// <param name="tran">The Ingres transaction to use.</param> 
        /// <returns>The Id for the current application.</returns>
        private string GetApplicationId(IngresConnection conn, IngresTransaction tran)
        {
            string id = null;

            string sql = @"
                          SELECT
                              ApplicationId
                          FROM
                              aspnet_Applications
                          WHERE LoweredApplicationName = ?
                         ";

            // Create the new command and enrol in the current transaction
            IngresCommand cmd = new IngresCommand(sql, this.conn);

            cmd.Transaction = this.tran;

            cmd.Parameters.Add("LoweredApplicationName", DbType.String).Value = this.config.ApplicationName.ToLower();

            conn.Open();

            IngresDataReader reader = cmd.ExecuteReader();

            if (reader != null)
            {
                if (reader.HasRows)
                {
                    reader.Read();

                    // Retrieve the Id
                    id = DBUtil.ColValAsString(reader, "ApplicationId");

                    reader.Close();
                }
                else
                {
                    // Close the reader.
                    reader.Close();

                    // We don't have an application so create one.
                    this.CreateApplication(this.config.ApplicationName, out id);
                }
            }

            // Mark the application Id as current so that we don't have to fetch it from the database
            // again unless it changes.
            this.config.IsApplicationIdCurrent = true;

            // Close the connection
            conn.Close();

            return id;
        }
        /// <summary>
        /// Returns an integer value that is the count of all the users in the data source where 
        /// the <c>LastActivityDate</c> is greater than the current date and time minus the 
        /// <c>UserIsOnlineTimeWindow</c> property. The <c>UserIsOnlineTimeWindow</c> property is an integer 
        /// value specifying the number of minutes to use when determining whether a user is online.
        /// </summary>
        /// <remarks>
        /// This is the main implementation for the <c>GetNumberOfUsersOnline</c> method of the provider. Please
        /// see the corresponding method in the Facade, which calls this method, for full documentaion. 
        /// </remarks>
        /// <param name="conn">The Ingres connection to use.</param>
        /// <param name="tran">The Ingres transaction to use.</param>
        /// <returns>The number of users online.</returns> 
        internal int GetNumberOfUsersOnline(IngresConnection conn, IngresTransaction tran)
        {
            TimeSpan onlineSpan = new TimeSpan(0, Membership.UserIsOnlineTimeWindow, 0);
            DateTime compareTime = DateTime.Now.Subtract(onlineSpan);

            string sql = @"
                            SELECT
                                Count(*)
                            FROM
                                aspnet_Membership,
                                aspnet_Applications,
                                aspnet_Users
                            WHERE
                                aspnet_Users.LastActivityDate              > ?
                            AND aspnet_Applications.LoweredApplicationName = ?
                            AND aspnet_Membership.ApplicationId            = aspnet_Applications.ApplicationId
                            AND aspnet_Users.UserId                        = aspnet_Membership.UserId
                           ";

            // Create the Ingres command.
            IngresCommand cmd = new IngresCommand(sql, this.conn);

            cmd.Transaction    = this.tran;
            cmd.CommandTimeout = this.config.CommandTimeout;

            // Add the required parameters.
            cmd.Parameters.Add("CompareDate", DbType.DateTime).Value          = compareTime;
            cmd.Parameters.Add("LoweredApplicationName", DbType.String).Value = this.config.ApplicationName.ToLower();

            // Execute the command to obtain the number of users online
            int numOnline = Convert.ToInt32(cmd.ExecuteScalar());

            return numOnline;
        }