Question can't connect to a local database

mmy

Member
Joined
Oct 5, 2007
Messages
24
Programming Experience
1-3
Hi,

I have a database (test) with one table (names) in it. I'm using MySQL 5.0.5, installed with WAMP.

In Visual Studio 2005 I'm trying to connect to this database.

I use the following code
VB.NET:
Imports System.Data.SqlClient

Dim strConnection As String = "Data Source=localhost;User ID = marco; Password=marco; Initial Catalog=test"
Dim objConnection As SqlConnection = New SqlConnection(strConnection)
Try
   objConnection.Open()
   MessageBox.Show("connection ok")
   objConnection.Close()
Catch ex As Exception
   MessageBox.Show(ex.Message)
End Try

However, I receive an error saying I can't establish a connection to the server (and when connecting to SQL Server 2005 -> default settings don't allow remote connections). However, In MySQL I can't find such a property.

I receive the same error when I'm using the following connection string

VB.NET:
mySQLConnString = "Server=localhost;Database=test;Uid=marco;Pwd=marco;"

Can anybody help me please? I'm not sure if the syntax in visual basic is wrong, or if I'm missing an option in MySQL itself...
 
I knew that site before, but couldn't get it to work...

But this code seems to work ok
VB.NET:
Imports MySql.Data.MySqlClient

Dim conn As MySqlConnection = New MySqlConnection
conn.ConnectionString = "server=localhost;user id=root;password=;database=bkm2"
conn.Open()

Although, you have to download a mysql connector and set a reference to it. It's described at this tutorial http://www.vbmysql.com/articles/vbnet-mysql-tutorials/the-vbnet-mysql-tutorial-part-3
 
Back
Top