0

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
3
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by artemix22
0

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

0

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

Edited by artemix22

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.