我安装了mysql和连接器但由于某种原因它不会连接到数据库!我试图用一个我用000webhost.com创建的mysql数据库来创建一个简单的登录系统但是每次我尝试登录时都会遇到无法建立连接的错误?
这是我的代码:
If username.Text = "" Or password.Text = "" Then
MsgBox("Please enter a Username and Password")
Else
'Connect to Database
Dim connect As New MySqlConnection("server=host;user id=dbuser;Password=pass;database=dbname")
Try
connect.Open()
Catch myerror As MySqlException
MsgBox("Error couldn't establish a connection to the database")
End Try
'SQL Query to Get the Details
Dim myAdapter As New MySqlDataAdapter
Dim sqlquery = "Select * From User where username = '" + username.Text + "' And password = '" + password.Text + "'"
Dim myCommand As New MySqlCommand
myCommand.Connection = connect
myCommand.CommandText = sqlquery
'Starting The Query
myAdapter.SelectCommand = myCommand
Dim mydata As MySqlDataReader
mydata = myCommand.ExecuteReader
'To check the Username and password and to validate the login
If mydata.HasRows = 0 Then
MsgBox("Invalid Login")
Else
MsgBox("UserName N Password is accepted!")
End If
End If