static void Main(string[] args) { MySqlConnectionStringBuilder connStrBuilder = new MySqlConnectionStringBuilder(); connStrBuilder.UserId = "root"; connStrBuilder.Password = ""; connStrBuilder.Host = "localhost"; connStrBuilder.Port = 3306; connStrBuilder.Database = "test"; connStrBuilder.Pooling = false; connStrBuilder.ClientInteractive = true; MySqlConnection myConn = new MySqlConnection(connStrBuilder.ToString()); MySqlCommand command = new MySqlCommand("select 1", myConn); myConn.Open(); //If interactive_timeout is set to a value less than 60, the command will throw exception: //Lost connection to MySQL server during query Thread.Sleep(new TimeSpan(0, 0, 60)); try { command.ExecuteNonQuery(); } catch (MySqlException e) { if (e.Code == 2013) Console.WriteLine(e.Message); } }
Sub Main() Dim connStrBuilder As MySqlConnectionStringBuilder = New MySqlConnectionStringBuilder() connStrBuilder.UserId = "root" connStrBuilder.Password = "" connStrBuilder.Host = "localhost" connStrBuilder.Port = 3306 connStrBuilder.Database = "test" connStrBuilder.Pooling = False connStrBuilder.ClientInteractive = True Dim myConn As MySqlConnection = New MySqlConnection(connStrBuilder.ToString()) Dim command As MySqlCommand = New MySqlCommand("select 1", myConn) myConn.Open() 'If interactive_timeout is set to a value less than 60, the command will throw exception: 'Lost connection to MySQL server during query Thread.Sleep(New TimeSpan(0, 0, 60)) Try command.ExecuteNonQuery() Catch ex As MySqlException If (ex.Code = 2013) Then Console.WriteLine(ex.Message) End If End Try End Sub
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2