I just want to connect my mysql with vb.net code as below: But,for some reason I cant figure out the problem
i have also added the mysqldata.dll in my reference. all the input in connection string is valid and there is no error in the code. it just shows cannot connect all the time.

Public Class Form1
    Dim oSQLConn As SqlConnection = New SqlConnection()

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


        oSQLConn.ConnectionString = "server = localhost; user id = root; password = chris; database = retail;"

        TryImports System.Data.SqlClient


            oSQLConn.Open()
            MsgBox("Connection Open !")
        Catch ex As Exception
            MsgBox("cannot connect")
        End Try
        oSQLConn.Close()
    End Sub
End Class

Recommended Answers

All 2 Replies

I guess the problem is in oSQLConn.ConnectionString = "server = localhost; user id = root; password = chris; database = retail;" please check this.

change into like this :

Imports MySql.Data.MySqlClient
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Using oSQLConn As New MySqlConnection("server=localhost;user=root;password=chris;database=retail")
                oSQLConn.Open()
                MsgBox("Connection Open !")
                oSQLConn.Close()
            End Using
        Catch ex As Exception
            MsgBox("cannot connect")
        End Try
    End Sub
End Class
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.