附加信息:使用方法'mysql_native_password'对主机''for user'进行身份验证失败,并显示消息:用户'''user-PC'拒绝访问(使用密码:否) [英] Additional information: Authentication to host '' for user '' using method 'mysql_native_password' failed with message: Access denied for user ''@'user-PC' (using password: NO)

查看:1748
本文介绍了附加信息:使用方法'mysql_native_password'对主机''for user'进行身份验证失败,并显示消息:用户'''user-PC'拒绝访问(使用密码:否)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到这样的错误:



I am having error like this :

Additional information: Authentication to host '' for user '' using method 'mysql_native_password' failed with message: Access denied for user ''@'user-PC' (using password: NO)





此代码:





in this code:

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
       Dim user As String = TextBoxUserName.Text
       Dim pass As String = TextBoxPassword.Text

       cn.Open()
       cmd.CommandText = "SELECT * FROM login_table WHERE username= '" & TextBoxUserName.Text & "' and password= '" & TextBoxPassword.Text & "', cn"
       cmd.Connection = cn
       cmd.Parameters.Add(New MySqlParameter("@UserName", TextBoxUserName.Text))
       cmd.Parameters.Add(New MySqlParameter("@Password", TextBoxPassword.Text))
       cmd.Connection = cn
       'cmd.EndExecuteReader = reader

       If reader.HasRows() Then
           MessageBox.Show("Login success!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information)
           'Form1.Show()
           'Me.Close()
           Button1.Show()
           Button2.Show()
           Button5.Show()
           TextBoxPassword.Clear()
       Else

           MsgBox("Invalid Login information.!", MessageBoxButtons.OK, MessageBoxIcon.Information)
       End If
       cn.Close()

推荐答案

你需要编辑此基本示例以反映您自己的查询,变量和连接字符串。如果您发现此回复有帮助,请将其标记为解决方案。我在评论中向你指出了一些事情。



这一行都是错误的,你的一个问题是最后应该在之前,然后结束。你也应该使用(Put Query这里)块。

You will need to edit this basic example to reflect your own queries, variables and connection string. If you found this reply helpful, please mark it as a solution. I have pointed out a few things to you in the comments.

This whole line is wrong and one of your problems is the " at the end should be before the , at then end. You should also be using ("Put Query here") blocks.
"SELECT * FROM login_table WHERE username= '" & TextBoxUserName.Text & "' and password= '" & TextBoxPassword.Text & "', cn"





试试这个:





Try this:

Dim SelectID As Integer
Dim UserName As String = "Tom"
Dim iUserGuid As String = "5266-2453-4523-3562" 

'Create your own variable for your parameter placeholder. The above are only examples.  
 
Dim MysqlConn As MySqlConnection 'Creates a MySQL Connection should one be called
Dim MySqlConnectionString As String = "http://www.connectionstrings.com/mysql/" 
'Read up on connection strings from the link i gave you, and put your connection string in this variable above.      
'Don't use these '' symbols, use `` instead.

            Try

                MysqlConn = New MySqlConnection()
                MysqlConn.ConnectionString = MySqlConnectionString
                Query = "SELECT `session` FROM `databasename`.`yourtablehere` WHERE `username` = @username AND `guid` = @guid;" 

'Do not concatenate queries. Use Parameters. 

'Connect your query command to the connection.

                Dim QueryComCheck As New MySqlCommand(Query, MysqlConn) 
                QueryComCheck.Parameters.AddWithValue("@username", UserName)

'@username and @guid is a placeholder for the declared declarations UserName and iUserGuid.  
                QueryComCheck.Parameters.AddWithValue("@guid", iUserGuid)

'Check if the connection is open or not, if its closed, open it... 
'Don't assume something, check it first.  

                If MysqlConn.State = ConnectionState.Closed Then
                    MysqlConn.Open()
                End If
                Using reader As MySqlDataReader = QueryComCheck.ExecuteReader

'Check to see if there are any rows. 

                    If reader.HasRows Then 

'Do While Reader.Read returns false by default if nothing to read.

                        Do While reader.Read() 
'Debug.WriteLine(reader.GetString(1)) 'Write the result to console. 

                            If CBool(reader.GetString("session")) = True Then

'Do your own checking here and handle how you get your data. 

                                SelectID = CInt(reader.GetString("session"))

                            End If

                        Loop

                    End If

                End Using

'By using the reader, you don't need to dispose of the resources of mysql, as the using blocks does this for you. 

            Catch GetSessionFromUser As Exception
'Handle Errors here
            End Try


这篇关于附加信息:使用方法'mysql_native_password'对主机''for user'进行身份验证失败,并显示消息:用户'''user-PC'拒绝访问(使用密码:否)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆