public static void UpdateMaxAllowPacket(this MySqlConnection conn) { var cmd = new MySqlCommand("SELECT @@global.max_allowed_packet", conn); var reader = cmd.InternalExecuteReader(); while (reader.Read()) { ulong value = reader.GetULong(0); if (value >= int.MaxValue) { throw new NotSupportedException("this version not support max allowed packet > int.MaxValue"); } conn.SetMaxAllowedPacket((int)value); //cast down break; } reader.InternalClose(); }