Search code examples
c#mysqlvisual-studioconnectiondatabase-connection

When connecting to the mysql database, an exception appears


can anyone help me, I am trying to connect mysql database, the server details are entered correctly, but when I call the open method, the program throws an exception.

enter image description here

I also used Server explorer, in this case the program sees the server, but I don't know how to use the database connected through Server explorer, that is, how to add it to the project itself.

enter image description here

Please tell me how to fix this error, or how to use the database through Server explorer.

This is how I connect to the database:

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BDtest
{
    class Program
    {
        static void Main(string[] args)
        {
            SqlConnection sqlConnection = new SqlConnection("server=localhost;user=root;database=clothing_shop;password=****;");
            sqlConnection.Open();
            string queri = "select world.countrylanguage.CountryCode from world.countrylanguage where CountryCode = 'ARM'";
            SqlCommand cmd = new SqlCommand(queri, sqlConnection);
            var value = cmd.ExecuteScalar().ToString();
            Console.WriteLine(value);
        }
    }
}

Solution

  • Looking at your code, you are using System.Data.SqlClient which is a .NET Data Provider for SQL Server.

    In your question you state that you try to connect to a mysql database. Use the appropriate nuget package for that