Question

Exception information: Exception type: MySqlException

Exception message: error connecting: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.

The above is the error that I am getting in the event viewer. This exception only seems to occur on our development server. It is an in-house warehouse management and private company webshop. We have less than a 100 users on it at a given time and this is what I understand:

  • Connection cannot be made because there are too many open threads.

Things that I have done to try to solve the issue:

  • Force enable "Pooling=True;" in the application's connectionstring.
  • Force "Max Pooling Size=1000;" in the application's connectionstring.
  • Reduce the connection thread idle lifetime from 8 hours down to 2 hours in MySQL Administrator.
  • Increase the max connections allowed in the MySQL Administrator to 1000.

This still seems to cause the same issues and I am currently at my wits end. To damage control this issue I am killing users with threads older than an hour or two.I have monitored that during these crashes there are only around 108 connections at maximum. One particular time it stopped accepting connections when there were 40 IDLE threads.

Below is the code used to make transactions.

   /// <summary>
   /// Begin a database transaction.
   /// </summary>
   /// <returns>The database connection.</returns>
    public DbTransaction BeginTransaction()
    {
        if (_DbConnection.State != ConnectionState.Open)
        {
            _DbConnection.Open();
        }
        return _DbConnection.BeginTransaction();
    }

    /// <summary>
    /// Commit a database transaction.
    /// </summary>
    /// <param name="transaction">The database connection.</param>
    public void CommitTransaction(DbTransaction transaction)
    {
        if (transaction != null)
        {
            transaction.Commit();
            transaction.Dispose();
        }
        if (_DbConnection != null)
        {
            _DbConnection.Close();
        }
    }

    /// <summary>
    /// Rollback a database transaction.
    /// </summary>
    /// <param name="transaction">The database transaction.</param>
    public void RollbackTransaction(DbTransaction transaction)
    {
        if (transaction != null)
        {
            transaction.Rollback();
        }
    }
Was it helpful?

Solution

Try actually saving your connection strings after modifying them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top