连接到mysql数据库失败

时间:2017-02-19 20:08:42

标签: mysql .net

当我尝试执行以下代码以在文本框中输入值时,会出现错误说明:对主机进行身份验证''对于用户''使用方法' mysql_native_password'消息失败:用户访问被拒绝'' Adam-PC' (使用密码:否)

Public Sub TextBox1_TextChanged(sender as Object,e As EventArgs)处理Datetxt.TextChanged         Dim ConnectionString As String         Dim con As New MySqlConnection

    ConnectionString = "server=localhost;user id=root;database=river_data;allowuservariables=True"";Integrated Security=True;MultipleActiveResultSets=True;"

    Dim cmd As MySqlCommand
    Dim query As String = "SELECT date FROM river-derwent-keswick-portinscale WHERE(`date` = '01.01.2013') "
    cmd = New MySqlCommand(query, con)
    con.Open()

    Dim myreader As MySqlDataReader = cmd.ExecuteReader()
    If myreader.Read() Then
        Datetxt.Text = myreader.GetValue(0)
    Else
        Me.Close()
        HomeForm.Show()
    End If
    myreader.Close()

1 个答案:

答案 0 :(得分:0)

ConnectionString = "server=localhost;user id=root;database=river_data;allowuservariables=True"";Integrated Security=True;MultipleActiveResultSets=True;"

看起来用户部分是错误的。尝试:

ConnectionString = "server=localhost;user=root;database=river_data;allowuservariables=True"";Integrated Security=True;MultipleActiveResultSets=True;"