Question MySQL connection to VB.

Joaogl

New member
Joined
May 29, 2012
Messages
2
Programming Experience
1-3
Hello,

Im trying to do a simple application to send and read variables in the/to My DataBase.

Myy code:

PHP:
Imports MySql.Data.MySqlClientPublic Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim conn As MySqlConnection        conn = New MySqlConnection        conn.ConnectionString = "Server=*****;User Id=******;Password=*****;Database=******"        Try            conn.Open()        Catch ex As Exception            MsgBox(ex.Message)        End Try        Dim myadapter As New MySqlDataAdapter        Dim sqlquery = "SELECT * FROM account WHERE fname='" & TextBox1.Text & "' AND lname='" & TextBox2.Text & "'"        Dim mycommand As New MySqlCommand        mycommand.Connection = conn        mycommand.CommandText = sqlquery        myadapter.SelectCommand = mycommand        Dim mydata As MySqlDataReader        mydata = mycommand.ExecuteReader        If mydata.HasRows = 0 Then            MsgBox("Bad")        Else            MsgBox("Good")            Me.Hide()        End If    End SubEnd Class

Problem it always say:
VB.NET:
Unable to connect to any of the specified MsSQL hosts.


Why this appens?
 
Your code is basically unreadable. Please use
 tags and just post the code as plain text.

Having said that, if the error message says that it cannot connect to the specified server then you need to make sure that the server is configured correctly and that you have provided a valid connection string for that server.
 
Back
Top