none
why my program always hang or not responding after a few minute?

    Question

  • Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        
            Try
                'Dim query As String = "SELECT * FROM lamps WHERE id =1"
                Dim query As String = "SELECT * FROM lamps ORDER BY id DESC"
                Dim connection As New MySqlConnection(connStr)
                Dim cmd As New MySqlCommand(query, connection)
                connection.Open()
                Dim reader = cmd.ExecuteReader
                If (reader.Read()) Then  'if data exist
                    lampvalue = reader.GetString(1)  'Get data from column 1 (lampstatus)
                    If (lampvalue <> temporary_1) Then
                        SerialPort1.Write(Chr(lampvalue))
                        temporary_1 = lampvalue
                    End If
                    reader.Close()
                    connection.Close()
                End If
            Catch ex As Exception
                '      Console.WriteLine(ex.Message)
            End Try

            Try
                ' Dim value As String
                Dim temperature As Double
                Dim datetime As Date
                datetime = Now
                Text_date.Text = datetime.ToShortDateString
                Text_time.Text = datetime.ToLongTimeString

                '  Label1.Text = dataserial.ToString
                ' value = dataserial.ToString
                ' value = SerialPort1.ReadByte.ToString
                dataserial = SerialPort1.ReadByte
                temperature = (1.96) * dataserial
                Label1.Text = temperature.ToString
                Label5.Text = dataserial

                If (dataserial <> temporary) Then    
               Dim query As String = "INSERT INTO lamps (date,time, Temperature_value) VALUES ('" & Text_date.Text & "','" & Text_time.Text & "','" & Label1.Text & "')"
                    Dim connection As New MySqlConnection(connStr)
                    Dim cmd As New MySqlCommand(query, connection)
                    Dim rowsEffected As Integer = 0
                    connection.Open()
                    rowsEffected = cmd.ExecuteNonQuery
                    temporary = dataserial
                    connection.Close()

                End If

            Catch ex As Exception
                Console.WriteLine(ex.Message)
            End Try
        End Sub

    when i pressed start debugging ,the msg will pop out at below 

    A first chance exception of type 'System.TimeoutException' occurred in System.dll
    A first chance exception of type 'System.Data.SqlTypes.SqlNullValueException' occurred in MySql.Data.dll
    A first chance exception of type 'System.TimeoutException' occurred in System.dll
    A first chance exception of type 'System.Data.SqlTypes.SqlNullValueException' occurred in MySql.Data.dll

    i hope anyone can help me solve this problem...thank you.

    Sunday, March 10, 2013 5:33 AM

Answers

All replies