Access Denied

I am trying to connect to MySQL from c# with xampp. I dont know what is wrong with my code that it says:

"Authentication to host 'localhost' for user 'root' using method 'mysql_native_password' failed with message : Access denied for user 'root'@'localhost' (using password:YES)"

my code is as follows:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data;
using MySql.Data.MySqlClient;

namespace CZCMNHS
{
public class dbcon
{

    public MySqlConnection cnn;
    public string server;
    public string database;
    public string uid;
    public string password;
    int flag = 0;
    public int Flag
    {
        get { return flag; }

    }

    public dbcon()
    {
        server = "127.0.0.1";
        database = "dbenroll";
        uid = "root";
        password = "sti2017";
        string constring;

        constring = "datasource=" + server + ";" + "PORT=3306;DATABASE=" + database + ";" + "USERNAME=" + uid + ";" + "PASSWORD =" + password + ";";
        string query = "SELECT * FROM users"; 
        cnn = new MySqlConnection(constring);
        MySqlCommand cmd = new MySqlCommand(query, cnn);
        cmd.CommandTimeout = 60;
        MySqlDataReader reader;

        //conString = "server=localhost;port=3306;database=czcmnhs2017;uid =root@localhost;pwd=sti*2017;";
        //MySqlConnection cnn = new MySqlConnection(conString);
        //string query ="SELECT * FROM 
        MySqlCommand mysqlcmd = new MySqlCommand(); 

       
        try
        {
            if (!cnn.Ping())
            {
                cnn.Open();
                flag = 1;
            }
        }
        catch (Exception e)
        {
            flag = 0;
            MessageBox.Show(e.Message);
        }
    
    }
}

}

i really need this.. Thanks.

0
edit delete
are you sure?
asked Josielyn Huliganga

1 answer

I understand. happy wheels game.

0
edit delete
are you sure?
answered jenny han

Post an answer but please log in first

Post Answer
  1. Please log in to post answer

Similar Questions

Tagsfor this question

Forumall questions