Well i somehow failed to use the search on this site.

How do i connect to an online mysql database via VB.NET?
I did lot's of search the past few days
Could not find my answer.

Imports System.Data.SqlClient

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim connetionString As String
        Dim cnn As SqlConnection
        connetionString = "Data Source=HOST;Initial Catalog=DBNAME;User ID=USER;Password=PASS"
        cnn = New SqlConnection(connetionString)
        Try
            cnn.Open()
            MsgBox("Connection Open ! ")
            cnn.Close()
        Catch ex As Exception
            MsgBox("Can not open connection ! ")
                End Try
    End Sub
End Class

I'm guessing using SqlClient.SqlConnection (That it MS SQL) won't work with MySQL.
Follow the link in adatapost's message to get the mysql connector and try using that, with the appropriate connection string.

Edited 5 Years Ago by adam_k: n/a

Add a reference to the assembly MySql.Data and include the MySql.Data.MySqlClient namespace. Instantiate a new MySqlConnection connection object. Set the connection string and open the connection.

Imports MySql.Data.MySqlClient <-- gives me error and the reference is not in the list of references. :(any suggestions?

First of all download MySql Connector/net and add the reference of Mysql.Data.Dll to your project.

Could not edit post

Imports MySql.Data.MySqlClient

Public Class Form1

    Public myConnection As MySqlConnection = New MySqlConnection()

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        myConnection.ConnectionString = "Server=HOST;Database=DB;Uid=USER;Pwd=PASS;"
        Try
            myConnection.Open()
            MsgBox("Success!")
            myConnection.Close()
        Catch ex As Exception
            MsgBox("Can not open connection!")
            myConnection.Close()
        End Try
    End Sub
End Class

still gives me Can not open connection tho the credentials are right

This article has been dead for over six months. Start a new discussion instead.