0

我正在开发一个基于 Windows 的 VB.NET 应用程序,它与 mysql 作为后端和 Web 服务器一起使用。我正在使用 Web 服务 (asmx) 连接到数据库,并且所有操作都运行良好。有时,对于某些 SELECT 查询,它不会产生任何结果(也没有错误),而对于同一个查询,它会在一小时后或第二天产生结果。由于这种行为,我找不到任何错误提示并继续该项目。

如果您能告诉我正在发生的事情,请提前致谢

代码如下

<SoapHeader("Authentication")> _
<WebMethod(Description:="Get the result from sql query - Returns a Dataset")> _
Public Function ExecuteQuery(ByVal strQuery As String) As DataSet

    Dim ds As DataSet = New DataSet 'create a DataSet to hold the results
    If decryptString(Authentication.Username) = "bla bla" AndAlso decryptString(Authentication.Password) = "bla blah" Then

        Try

            'create a MySqlCommand to represent the query
            If sqlConn.State = ConnectionState.Closed Then
                sqlConn = New MySqlConnection(conStr)
                sqlConn.Open()
            End If

            Dim sqlcmd As MySqlCommand = sqlConn.CreateCommand()
            sqlcmd.CommandType = CommandType.Text
            sqlcmd.CommandText = strQuery

            'create a MySqlDataAdapter object
            Dim sqlDa As MySqlDataAdapter = New MySqlDataAdapter
            sqlDa.SelectCommand = sqlcmd

            Try
                'fill the DataSet using the DataAdapter
                sqlDa.Fill(ds, "Results")
            Catch ex As Exception
                Throw New ApplicationException("Error-luckie's server 1 " & ex.Message)
            End Try

        Catch ex As Exception
            Throw New ApplicationException("Error-luckie's server 2 " & ex.Message)
        Finally
            sqlConn.Close()
            sqlConn.Dispose()
        End Try

    End If
    Return ds

End Function
4

0 回答 0