I am trying to connect to Mysql database through vb.net
However I run into the error:
Unable to connect to any of the specified MySQL hosts
Here is the code:
Imports MySql.Data.MySqlClient
Public Class DBProject_1
Dim MysqlConn As MySqlConnection
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MysqlConn = New MySqlConnection
MysqlConn.ConnectionString = "server=localhost;userid=root;password=root;database=My_Mysql_Database"
Try
MysqlConn.Open()
MessageBox.Show("Connection Successful")
MysqlConn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
MysqlConn.Dispose()
End Try
End Sub
End Class
I have even tried to use
MysqlConn.ConnectionString = "server=**127.0.0.1**;userid=root;password=root;database=My_Mysql_Database"
This may be the reason:
When I test connection of the Mysql database in Mysql Workbench the test fails.
The error is Failed to Connect to Mysql at 127.0.0.1:3306 with user root
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…