title: MySqlConnection Connect() Method very slow to throw exception when DB is gone C#
body: <p>i'm creating a C# Server, that opens a named pipe and collects data that clients send to it. Basically, i'm storing the collected information in a mysql database, using .NET MySql Connector and the MySqlConnection Class. I also added a fallback rule, which in case the DB is out of reach, buffers the info sent by the clients in an SQL file and imports it into the DB when it is available again.
  Everything works fine, except when the DB is gone completely (for example when the server that runs the DB is not on the network anymore because it crashed), the Connect() Method takes forever to throw an exception. This is unacceptable, because the clients send in A LOT of data. Is there any way to fix this? If the query fails because a table is not there or something like that, it returns an error immediately. </p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using log4net;
  using MySql.Data.MySqlClient;
  
  namespace PipeServer
  {
      class MySqlConnector
      {
          //register logger
          private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  
          public delegate void MessageReceivedHandler(string message);
          public event MessageReceivedHandler MessageReceived;
  
          private string host;
          private string database;
          private string user;
          private string password;
          private MySqlConnection connection;
          private List&lt;string&gt; rows = new List&lt;string&gt;();
  
  
  
          public MySqlConnector()
          {
              this.host = Settings.Default.db_host;
              this.database = Settings.Default.db_schema;
              this.user = Settings.Default.db_user;
              this.password = Settings.Default.db_pw;
              string myConnectionString = "SERVER=" + this.host + ";" +
                          "DATABASE=" + this.database + ";" +
                          "UID=" + this.user + ";" +
                          "PASSWORD=" + this.password + ";";
  
              connection = new MySqlConnection(myConnectionString);
  
  
  
  
          }
  
          public bool Connect()
          {
              if (connection.State != System.Data.ConnectionState.Open)
              {
                  try
                  {
                      connection.Open();
                      this.MessageReceived("Connected to Database");
                      return true;
                  }
                  catch (MySqlException ex)
                  {
                      log.Error("failed to connect! mysql error: " + ex);
                      this.MessageReceived("No Database connection - Error: "+ex);
                      return false;
                  }
  
              }
              else
              {
                  this.MessageReceived("Connected to Database");
                  return true;
              }
  
          }
          .
          .
          .
      }
  }
  </code></pre>
  
  <p>Any hint is highly appreciated!Thanks in advance!</p>