Mysql Localhost访问被拒绝VB.Net

时间:2015-07-25 09:25:28

标签: mysql vb.net

我在VB.net中有登录表单 但是我遇到问题,如果我访问我的localhost,以前代码工作,但在我离开VS并再次返回后,我遇到了这样的问题http://i.imgur.com/SfMghZj.png

这是我的源代码

 MySqlConn = New MySqlConnection
    MySqlConn.ConnectionString = "server=localhost;userid=root;password=***;database=exodium"
    Dim Reader As MySqlDataReader
    Try
        MySqlConn.Open()
        Dim Query As String
        Query = "select * from exodium.member where Username='" & UsernameTxt.Text & "' and Password='" & PasswordTxt.Text & "'"
        Command = New MySqlCommand(Query, MySqlConn)
        Reader = Command.ExecuteReader
        Dim count As Integer
        count = 0
        While Reader.Read
            count = count + 1
        End While
        If count = 1 Then
            Loading.Show()
        ElseIf count > 1 Then
            MessageBox.Show("Duplicate !")
        Else
            MessageBox.Show("Not Correct !")
        End If
        MySqlConn.Close()
    Catch ex As MySqlException
        MessageBox.Show(ex.Message)
    Finally
        MySqlConn.Dispose()
    End Try

这是我的Localhost http://i.imgur.com/CfeOHuh.png 谁有人可以帮忙?谢谢T_T

2 个答案:

答案 0 :(得分:1)

It may be possible of that you don't have permission on mysql database.
Look into mysql.user table that you have entry for localhost and that password[Will be in encrypted form].
if not please insert one and use 

CREATE USER 'root'@'localhost' IDENTIFIED BY '14253690';
GRANT ALL PRIVILEGES ON * . * TO 'root'@'localhost' IDENTIFIED BY '14253690';
FLUSH PRIVILEGES;

答案 1 :(得分:0)

 Try
            Dim MySqlConn As MySqlConnection
            Dim COMMAND As MySqlCommand
            MySqlConn = New MySqlConnection
            MySqlConn.ConnectionString = "server=localhost;user id=root;password=;database=exodium"
            Dim READER As MySqlDataReader
            MySqlConn.Open()
            Dim Query As String
            Query = "SELECT Username,Password FROM member"
            COMMAND = New MySqlCommand(Query, MySqlConn)
            READER = COMMAND.ExecuteReader

            While READER.Read

                Dim userNameDB = READER.GetString("Username")
                Dim PasswordDB = READER.GetString("Password")

                Dim userName As String = UsernameTxt.Text
                Dim Password As String = PasswordTxt.Text

                If userNameDB = userName And PasswordDB = Password Then
                    MessageBox.Show("Duplicate !")
                Else
                   MessageBox.Show("Not Correct !")
                End If

            End While
            MySqlConn.Close()
        Catch myerror As Exception
            MessageBox.Show(myerror.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try