title: C# MySQL Connector: Connection pools are not working
body: <p>I want to make use of the connection pooling so i could use the database without passing the MysqlConnection object to each class. I have a code like this:</p>
  <p>Main.cs:</p>
  <pre><code>namespace batman
  {
  
      class Program
      {
          static void Main(string[] args) 
          {
              using (MysqlConnection conn = new  MysqlConnection(&quot;Server=localhost;User=root;Database=test;Password=root;Min Pool Size=3;Max Pool Size=5;Pooling=True&quot;))
              {
                    MonitorClass monitor = new MonitorClass();
                    monitor.Run();
              }
  
             //...
          }
      }
  }
  </code></pre>
  <p>MonitorClass.cs:</p>
  <pre><code>namespace batman
  {
  
      public class MonitorClass
      {
  
          public void Run()
          {
  
              using (MySqlConnection conn = new MySqlConnection())
              using (MySqlCommand cmd = conn.CreateCommand())
              {
  
  
                  try
                  {
                      conn.Open();
                      cmd.CommandText = &quot;SELECT id, package_type FROM package_registry WHERE finish_time &lt;= @ftime&quot;;
                      cmd.Parameters.AddWithValue(&quot;@ftime&quot;, 0);
                      cmd.Prepare();
  
                      MySqlDataReader reader = cmd.ExecuteReader();
                      while (reader.Read())
                      {
                          int packageId = reader.GetInt32(0);
                          string packageType = reader.GetString(1);
  
                          Unirest.post(&quot;http://localhost/gears/ops/packagefinish&quot;)
                          .field(&quot;package&quot;, packageId)
                          .asStringAsync();
  
                          Console.WriteLine(&quot;[PackageMonitor] Package {0} ({1}) expired&quot;, packageId, packageType);
                      }
                  }
                  catch (MySqlException ex)
                  {
  
                  }
          }
          }
      }
  }
  </code></pre>
  <p>MonitorClass should take the connection from the connection pool.
  But once I run my program it throws System.InvalidOperationException with</p>
  <blockquote>
  <p>Additional information: Unable to connect to any of the specified MySQL hosts.</p>
  </blockquote>
  <p>at:</p>
  <blockquote>
  <p>cmd.Prepare();</p>
  </blockquote>
  <p>Now, i think I'm doing something wrong, but I couldn't figure out what exactly.</p>
  <p>Oracle docs says this</p>
  <blockquote>
  <p>The Connector/Net supports connection pooling for better performance and scalability with database-intensive applications. This is enabled by default. You can turn it off or adjust its performance characteristics using the connection string options Pooling, Connection Reset, Connection Lifetime, Cache Server Properties, Max Pool Size and Min Pool Size. See Section 5.2, “Creating a Connector/Net Connection String” for further information.</p>
  <p>Connection pooling works by keeping the native connection to the server live when the client disposes of a MySqlConnection. <strong>Subsequently, if a new MySqlConnection object is opened, it will be created from the connection pool, rather than creating a new native connection</strong>. This improves performance.</p>
  </blockquote>