using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using MySql.Data.MySqlClient; namespace MySqlTimeout1 { class Program { static void Main(string[] args) { string connectionString = "Data Source=localhost;Database=mysql;User Id=root;Password=password"; System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); try { ExecuteQuery(connectionString); Console.WriteLine("Did not timeout"); } catch (MySqlException e) { Console.WriteLine("Error: {0}", e); } sw.Stop(); Console.WriteLine("Execution Time: {0}", sw.Elapsed); Console.WriteLine("Press Enter to continue..."); Console.ReadLine(); } private static void ExecuteQuery(string connectionString) { using (var connection = new MySqlConnection(connectionString)) { connection.Open(); string commandText = @" SELECT SLEEP (45); "; using (MySqlCommand command = new MySqlCommand(commandText, connection)) { using (var reader = command.ExecuteReader()) { if (reader == null) throw new NullReferenceException(); reader.Read(); int nCount = reader.GetInt32(0); if (nCount != 0) throw new Exception("Unexpected result"); } } } } } }