0

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.

4
Contributors
11
Replies
21
Views
6 Years
Discussion Span
Last Post by AnooooPower
0
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
0

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 by adam_k: n/a

0

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?

0

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

0

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 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.