private void loadBtn_Click(object sender, EventArgs e) { try { MySqlCommand auth = new MySqlCommand("SELECT * FROM товары", serverSettings.serverConnection); MySqlDataReader rd = auth.ExecuteReader(); while (rd.Read()) { this.chart1.Series["Цена"].Points.AddXY(rd.GetString("название_товара"), rd.GetInt32("цена")); } serverSettings.serverConnection.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } 

The problem is the following, I wrote the code to display the graphs, the data of which is stored in the MySQL database (it did the database in Workbench), but when I start the program, I get a connection error like Connection. Please help me, I am new to programming, I don’t understand what is wrong ... Thanks in advance!

    1 answer 1

    We need to open the session. For example, mysqlconnection.Open ();

    • The connection was opened, but when I do some new action, an error pops up, that the connection is already open, how to fix it? - Alexander Monakhov
    • Close the connection after each action. - Vitaliy Scherban