0

I have a MVC project. I added MySql.data.dll file to my project. My localhost and mysql database is open. My database's name is proje and table is hasta_bilgileri.

I searched and tried too many solution but everytime I had different problems. What is the problem with my code? One of the last errors was

"Access denied for user root"

MySqlConnection con = new MySqlConnection("Server=localhost;Database=proje;Uid=root;password=123456;");
MySqlDataAdapter da = new MySqlDataAdapter("Select *From hasta_bilgileri", con);
DataSet table = new DataSet();
try
{
    con.Open();
}
catch (Exception e)
{
    Console.WriteLine(e);
}
da.Fill(table, "hasta_bilgileri");
con.Close();
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939

1 Answers1

0

It is not because of your script:

  1. Check the password in con! If it's correct:
  2. In phpmyadmin , in "User Accounts" create a new user!
  3. Make sure you are defining the "Host Name" as "%"!
  4. Declare a clear password that you can use it later in con
  5. Check Global Privileges!

Check here!

Done!

& more about your script:

  • catch(Exception e) is better to be like this: catch(MySqlException e).
  • Use Finally after catch exception for closing the connection!
  • First of all, thank you for your answer. I did your advices and now there is no warning in my code. Now, the problem is I don't show my data (which came from database) in the page. I asked a new question about that. https://stackoverflow.com/questions/51099082/how-can-we-use-the-data-which-came-from-database-in-c-sharp Can you look and answer it? Thank you so much.. – Hüseyin Argun Jun 29 '18 at 09:57