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.

Recommended Answers

All 11 Replies

me to didn't know can you teach us?
please ineed it in my project.

i did take a look at that i still failed to follow it :(

Sorry, I forgot my ~magic~ ball today. Can you please post the full source code? May be you need to install the mysql connector/net.

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.

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.

if i get that will the person using the program need to get it too to use it?

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

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.