title: MySqlException: The timeout period elapsed prior to obtaining a connection from the pool
body: <blockquote>
    <p>Exception information: 
    Exception type: MySqlException </p>
    
    <p>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.</p>
  </blockquote>
  
  <p>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:</p>
  
  <ul>
  <li>Connection cannot be made because there are too many open threads.</li>
  </ul>
  
  <p>Things that I have done to try to solve the issue:</p>
  
  <ul>
  <li>Force enable "Pooling=True;" in the application's connectionstring.</li>
  <li>Force "Max Pooling Size=1000;" in the application's connectionstring.</li>
  <li>Reduce the connection thread idle lifetime from 8 hours down to 2 hours in MySQL Administrator.</li>
  <li>Increase the max connections allowed in the MySQL Administrator to 1000.</li>
  </ul>
  
  <p>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.</p>
  
  <p>Below is the code used to make transactions.</p>
  
  <pre><code>   /// &lt;summary&gt;
     /// Begin a database transaction.
     /// &lt;/summary&gt;
     /// &lt;returns&gt;The database connection.&lt;/returns&gt;
      public DbTransaction BeginTransaction()
      {
          if (_DbConnection.State != ConnectionState.Open)
          {
              _DbConnection.Open();
          }
          return _DbConnection.BeginTransaction();
      }
  
      /// &lt;summary&gt;
      /// Commit a database transaction.
      /// &lt;/summary&gt;
      /// &lt;param name="transaction"&gt;The database connection.&lt;/param&gt;
      public void CommitTransaction(DbTransaction transaction)
      {
          if (transaction != null)
          {
              transaction.Commit();
              transaction.Dispose();
          }
          if (_DbConnection != null)
          {
              _DbConnection.Close();
          }
      }
  
      /// &lt;summary&gt;
      /// Rollback a database transaction.
      /// &lt;/summary&gt;
      /// &lt;param name="transaction"&gt;The database transaction.&lt;/param&gt;
      public void RollbackTransaction(DbTransaction transaction)
      {
          if (transaction != null)
          {
              transaction.Rollback();
          }
      }
  </code></pre>