Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27348

[RESOLVED] weirdly not finding records when reading from database

$
0
0
hey guys,

quick one for you.

I have a table in a database called 'dbcpman_jobs'.

My app submits asynchronous api calls which it needs to callback intermittently to check progress.
Once they hit jobstatus complete i can retrive bits of info and then remove the items from the jobs table.

The code that handles it is this:

Code:

......
        logentrytext = "[JOB-CALLBACK] Checking for callbacks..."
        Call dbcpman_log(logentrytext, logdirectory, logpath, logappend)

        Dim jobcheck As New MySqlDataAdapter("Select * FROM dbcpman_jobs WHERE failed='false'", cn)
        Dim jobcheck_table As New DataTable
        jobcheck.Fill(jobcheck_table)
        Dim jobrow As DataRow
        jobrow = jobcheck_table.Select("failed = 'false'").FirstOrDefault()

        If Not row Is Nothing Then

            Dim job_id As String = jobrow.Item("id")
            Dim job_jobid As String = jobrow.Item("jobid")
            Dim job_status As String = jobrow.Item("status")
            Dim job_dbxid As String = jobrow.Item("dbxid")

            logentrytext = "[JOB-CALLBACK] Starting asynchronous job callback for job " & job_jobid
            Call dbcpman_log(logentrytext, logdirectory, logpath, logappend)        ''''''Do some logging

            Dim jobcommand As String = "command=queryAsyncJobResult&jobId=" & job_jobid
            Dim fulljobapicheckurl = cpapiurl & jobcommand

            logentrytext = "[JOB-CALLBACK] API call to be used: " & fulljobapicheckurl
            Call dbcpman_log(logentrytext, logdirectory, logpath, logappend)        ''''''Do some logging
            Try
                Dim jobapicall As New System.Net.WebClient
                jobcheckresult = jobapicall.DownloadString(fulljobapicheckurl)
                logentrytext = "[JOB-CALLBACK] API response: " & jobcheckresult
                Call dbcpman_log(logentrytext, logdirectory, logpath, logappend)        ''''''Do some logging

            Catch ex As Exception
                ErrorTrap.errortext = ex.ToString
                ErrorTrap.Show()
            End Try

            If jobcheckresult.Contains("<jobstatus>1</jobstatus>") Then  ''If true, job has completed

                logentrytext = "[JOB-CALLBACK] Job " & job_jobid & " completed successfully"
                Call dbcpman_log(logentrytext, logdirectory, logpath, logappend)        ''''''Do some logging

                Dim doc As New System.Xml.XmlDocument
                doc.LoadXml(jobcheckresult) ''api_result contains xml returned from a http request.

                If doc.GetElementsByTagName("virtualmachine") IsNot Nothing Then
                    Dim elem As XmlNodeList = doc.GetElementsByTagName("virtualmachine").Item(0).ChildNodes
                    For Each item As XmlNode In elem
                        If item.Name.Equals("state") Then
                            new_vm_state += ((item.InnerText.ToString()) + Environment.NewLine)
                        ElseIf item.Name.Equals("hostname") Then
                            new_vm_hostname += ((item.InnerText.ToString()) + Environment.NewLine)
                        ElseIf item.Name.Equals("templatename") Then
                            new_vm_templatename += ((item.InnerText.ToString()) + Environment.NewLine)
                        ElseIf item.Name.Equals("cpunumber") Then
                            new_vm_cpunumber += ((item.InnerText.ToString()) + Environment.NewLine)
                        ElseIf item.Name.Equals("cpuspeed") Then
                            new_vm_cpuspeed += ((item.InnerText.ToString()) + Environment.NewLine)
                        ElseIf item.Name.Equals("memory") Then
                            new_vm_memory += ((item.InnerText.ToString()) + Environment.NewLine)
                        ElseIf item.Name.Equals("nic") Then
                            new_vm_netmask += ((item.ChildNodes.Item(3).InnerText.ToString()) + Environment.NewLine)
                            new_vm_gateway += ((item.ChildNodes.Item(4).InnerText.ToString()) + Environment.NewLine)
                            new_vm_ipaddress += ((item.ChildNodes.Item(5).InnerText.ToString()) + Environment.NewLine)
                            new_vm_macaddress += ((item.ChildNodes.Item(11).InnerText.ToString()) + Environment.NewLine)
                        ElseIf item.Name.Equals("instancename") Then
                            new_vm_instancename1 += ((item.InnerText.ToString()) + Environment.NewLine)
                        End If
                    Next
                End If

                Try
                    Dim myCommand As New MySqlCommand
                    Dim myAdapter As New MySqlDataAdapter
                    Dim SQL As String
                    myCommand.Connection = cn
                    cn.Open()
                    myAdapter.SelectCommand = myCommand
                    SQL = "DELETE FROM dbcpman_jobs WHERE jobid = '" & job_jobid & "'"
                    myCommand.CommandText = SQL
                    myCommand.ExecuteNonQuery()
                    cn.Close()

                    Dim new_vm_username As String = "clouduser"
                    Dim new_vm_password As String = GeneratePassword(10)
                    System.Threading.Thread.Sleep(1000)
                    Dim new_vm_support_username As String = "dbxsupport"
                    Dim new_vm_support_password As String = GenerateSupportPassword(10)

                    logentrytext = "[JOB-CALLBACK] Generated credentials for " & new_vm_username & " and " & new_vm_support_username
                    Call dbcpman_log(logentrytext, logdirectory, logpath, logappend)        ''''''Do some logging

                    cn.Open()
                    myAdapter.SelectCommand = myCommand
                    SQL = "INSERT into dbcpman_credentials(username1, username2, password1, password2, type, link) VALUES ('" & new_vm_username & "','" & new_vm_support_username & "','" & new_vm_password & "','" & new_vm_support_password & "','Server root logon','" & job_dbxid & "')"
                    myCommand.CommandText = SQL
                    myCommand.ExecuteNonQuery()
                    SQL = "INSERT into dbcpman_vm_boot(dbxid, ip, hostname) VALUES ('" & job_dbxid & "','" & new_vm_ipaddress & "','" & job_dbxid & "')"
                    myCommand.CommandText = SQL
                    myCommand.ExecuteNonQuery()
                    cn.Close()
                Catch ex As Exception
                    ErrorTrap.errortext = ex.ToString
                    ErrorTrap.Show()
                End Try

            ElseIf jobcheckresult.Contains("<jobstatus>0</jobstatus>") Then  ''If true, job is still pending
                logentrytext = "[JOB-CALLBACK] Job " & job_jobid & " is still pending"
                Call dbcpman_log(logentrytext, logdirectory, logpath, logappend)        ''''''Do some logging

            ElseIf jobcheckresult.Contains("<jobstatus>2</jobstatus>") Then  ''If true, job has failed
                logentrytext = "[JOB-CALLBACK] Job " & job_jobid & " has failed"
                Call dbcpman_log(logentrytext, logdirectory, logpath, logappend)        ''''''Do some logging

                Try
                    Dim myCommand As New MySqlCommand
                    Dim myAdapter As New MySqlDataAdapter
                    Dim SQL As String
                    myCommand.Connection = cn
                    cn.Open()
                    myAdapter.SelectCommand = myCommand
                    SQL = "UPDATE dbcpman_jobs SET failed = 'true' WHERE jobid = '" & job_jobid & "'"
                    myCommand.CommandText = SQL
                    myCommand.ExecuteNonQuery()
                    cn.Close()
                Catch ex As Exception
                    ErrorTrap.errortext = ex.ToString
                    ErrorTrap.Show()
                End Try

            Else
                logentrytext = "[JOB-CALLBACK] Job " & job_jobid & " returned no response"
                Call dbcpman_log(logentrytext, logdirectory, logpath, logappend)        ''''''Do some logging
            End If
        Else
            logentrytext = "[JOB-CALLBACK] No callback requests found"
            Call dbcpman_log(logentrytext, logdirectory, logpath, logappend)        ''''''Do some logging
        End If

    End Sub

If i look at the database, I can see there are 2 jobs sat in there at the moment, both 'failed=false', yet it doesn't do anything.
My logs report 'No callback requests found', like its not even reading the table at all.

The weird thing though is that the code just before this that creates the jobs works fine and when that bit of code has a new build to manage it adds a job successfully and then immediately makes a callback successfully once it gets to the code above, so i know that it can read the database just fine.

Any help appriciated!

Viewing all articles
Browse latest Browse all 27348

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>