title: MySQL Connection timeout on C#
body: <p>I just check other posts on stack overflow about the connection timeout, but looks like everybody fixed it using </p>
  
  <pre><code>com.CommandTimeout = int.MaxValue;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>dbaccess.ServerAddress = "Server=mysql;Database=MyDB;Connect Timeout=2147483;Uid=username;Pwd=mypassword";
  </code></pre>
  
  <p>Unfortunately, I still get this error message after 40 seconds:</p>
  
  <blockquote>
    <p>The timeout period elapsed prior to completion of the operation or the server is not responding.</p>
  </blockquote>
  
  <p>You can take a look at the two screenshots. </p>
  
  <p>MySQL Workbench works fine and it takes 48 seconds in executing the same query.</p>
  
  <p><a href="https://i.stack.imgur.com/tplLr.png" rel="nofollow noreferrer">ErrorMessage</a></p>
  
  <p><a href="https://i.stack.imgur.com/WHzFs.png" rel="nofollow noreferrer">Workbench</a></p>
  
  <p>I can not use limits to reduce the subset acquired because I am centralizing information split in different tables. A stored procedure can not be use since the information is stored in different mysql servers too.</p>
  
  <p>Any feedback will be much appreciated.</p>
  
  <p>Fernando</p>
  
  <p>EDIT:</p>
  
  <p>This is the code. I posted the image to show the execution time, not the error message. </p>
  
  <pre><code>public DataSet ExecuteQuery(string[] Query,  TableMap[] TableMappings)
  {
      //Mysql vars
      MySqlConnection con;
      MySqlCommand com;
      MySqlDataAdapter adapter;
      DataSet ds;
  
      con = new MySqlConnection();
      con.ConnectionString = _serveraddress;
  
      con.Open();
  
      com = con.CreateCommand();
      com.CommandType = System.Data.CommandType.Text;
  
      foreach (string st in Query)
      {
          com.CommandText = com.CommandText + st;
      }
  
      com.CommandTimeout = int.MaxValue;
  
      adapter = new MySqlDataAdapter(com.CommandText, con);
  
      foreach (TableMap tm in TableMappings)
      {
          adapter.TableMappings.Add(tm.SourceTable, tm.TableSet);
      }
  
      ds = new DataSet();
      adapter.Fill(ds);
  
      return ds;
  }
  </code></pre>