简体   繁体   English

Mysql Localhost访问被拒绝VB.Net

[英]Mysql Localhost Access Denied VB.Net

I Have Login Form in VB.net but i got problem if i access my localhost , previous the code is working, but after i leave the VS and go back again, i got problem like this http://i.imgur.com/SfMghZj.png 我在VB.net中有登录表单,但是如果访问我的localhost,则代码出现问题,但是在离开VS并再次返回后,出现了这样的问题http://i.imgur.com/ SfMghZj.png

this is my source code 这是我的源代码

 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

and this is my Localhost http://i.imgur.com/CfeOHuh.png anyone can help? 这是我的Localhost http://i.imgur.com/CfeOHuh.png任何人都可以帮忙吗? thanks T_T 谢谢T_T

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;
 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM