Question Relatively urgent help required.

JoshRose

New member
Joined
Jun 28, 2010
Messages
1
Programming Experience
Beginner
Okay, so here goes. My vb.net coding is not bad, I have been making Windows Form based Applications for at least 1.5 years, maybe two. However, I have been confronted with the task of creating a Web Browser Application. Not having much knowledge of this field, I opted for the Windows Presentation Foundation browser application (.NET Framework 3.5) which could be totally wrong.

Anyway, the issue I am having is connecting to a SQL Database hosted on a server by a friend. Using the exact same code but in a Windows Form Application, there are no issues at all, however when using a Windows Presentation Foundation browser application, it fails to connect with the error message:

Unable to connect to any of the specified MySQL hosts.

As I said, the identical code in Windows Form Application works perfectly with no errors. I'm sure it is something I have missed or over looked, but a second pair of eyes is always useful. The code is attached below, however the database setting such as password have been removed for security reasons:

VB.NET:
Imports MySql.Data
Class Page1

    Dim cmd As New MySqlClient.MySqlCommand
    Dim redturnValue As Object
    Dim connect As New MySqlClient.MySqlConnection("Database=studentdata;Data Source=SECURITYPLACEHOLDER;User Id=root;Password=SECURITYPLACEHOLDER")
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
        Try
            Dim reader As MySqlClient.MySqlDataReader
            connect.Open()
            cmd.Connection = connect
            MsgBox(cmd.IsPrepared)
            cmd.CommandText = "SELECT * FROM `year10` WHERE `Student Code`='ROS250'"

            reader = cmd.ExecuteReader
            While (reader.Read())
                If reader.HasRows = False Then
                    MsgBox("There is no record of this student")
                ElseIf reader.GetString("Student Name") = "Joshua Rose" Then
                    MsgBox("Success, the Student has been located!")
                End If
            End While
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            connect.Close()
        End Try
    End Sub
End Class

Regards,
JoshRose
 
Back
Top