3

How do I make a successful connection to db4free.net? Do I need to download the connector/net first? I cant seem to import MySql.Data.MySqlClient.

This is my sample code :

Imports System.Data.SqlClient
Imports mysql

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            Dim MySQLConnection = New SqlClient.SqlConnection
            MySQLConnection.ConnectionString = "server=db4free.net ;port=3306; user id=user; password=password; database=databasetest;"
            MySQLConnection.Open()
            MsgBox("Success!")
        Catch ex As Exception
            MsgBox("Failed!")
        End Try
    End Sub
End Class

Edit - By downloading the connector/net, I managed to Imports MySql.Data.MySqlClient. So thanks to adaam for pointing out the error as well Dim MySQLConnection = New SqlClient.SqlConnection. Here is my latest code. Managed to obtain that success message already. Am I doing right or still missing out some other important steps?

Imports System.Data.SqlClient
Imports MySql.Data.MySqlClient

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            Dim MySQLConnection = New MySqlConnection
            MySQLConnection.ConnectionString = "server=db4free.net ;port=3306; user=prav5ef; password=prav5eF; database=databasetest;"
            MySQLConnection.Open()
            MsgBox("Success!")
        Catch ex As Exception
            MsgBox("Failed!")
        End Try
    End Sub
End Class
MatSnow
  • 7,357
  • 3
  • 19
  • 31
Student
  • 432
  • 2
  • 10
  • 30
  • 1
    Yes this is what you need.. http://dev.mysql.com/downloads/connector/net/ – adaam Jul 22 '14 at 11:24
  • @adaam I have already downloaded that. Still unable to import that MySql.. – Student Jul 22 '14 at 11:28
  • In Visual Studio, in Solution Explorer, find References, right click, add reference, find the MySql package and add it as a reference to the project (see http://stackoverflow.com/a/1102310/1795862). This line: `Dim MySQLConnection = New SqlClient.SqlConnection` is also wrong, thats the System.Data.SqlClient type - not MySql – adaam Jul 22 '14 at 11:31
  • @adaam Should i tick all of it? There seems to be dupes. I am using Visual Basic 2013 http://postimg.org/image/yptasic7x/ – Student Jul 22 '14 at 11:38
  • I'd tick just one of the top three (`MySql.Data` v. 6.8.3) – adaam Jul 22 '14 at 11:40
  • This tutorial pretty much runs you through the whole process (and using VB as well): http://www.codeproject.com/Tips/493133/Connecting-to-MySQL-databases-using-VB-NET – adaam Jul 22 '14 at 11:42

0 Answers0