Is it possible to connect to a MySql database without MySql.Data.dll?

0

Whenever I'm going to use a MySql database in a console application or windows forms, you need to have the dll MySql.Data.dll within the application folder.

With this, I wonder if you have any way to use MySql without a dll. I thought about trying to use System.Data.SqlClient , but I do not know if it's possible.

    
asked by anonymous 20.08.2017 / 01:22

1 answer

2

% w / w ( reference here ) is unique to SQL Server ( as in this LINQ response ). Without a third-party DLL it's almost impossible to connect.

According to my research there are other ways to connect MYSQL to C # and it is not exclusive to System.Data.SqlClient . On this site I found some connector options for .NET:

I believe that MySql.Data.dll is the most used, the rest should no longer be used in the market (difficult even to find references). Here's an example using MySQLDriverCS found in this link .

    using MySQLDriverCS;
    using System.Data;
    MySQLConnection myConn;
    MySQLDataReader MyReader = null;
    try
    {
      myConn = new MySQLConnection(new MySQLConnectionString("123.456.789.100",
                                                    "mydatabase",
                                                    "user",
                                                    "pass").AsString);
      myConn.Open();
      string sql = "SELECT * FROM Table";
      MySQLCommand cmd = new MySQLCommand(sql, myConn);  
      MyReader = cmd.ExecuteReaderEx();
      while (MyReader.Read())
      {
        Console.WriteLine( MyReader["Product_Name"].ToString() );
      }
      MyReader.Close();       
    }
    catch(Exception ee)
    {
      Console.WriteLine( ee.ToString() );
    }
    finally
    {
       if (MyReader != null && !MyReader.IsClosed)
       {
          MyReader.Close();
       }
       if (myConn != null && myConn.State == ConnectionState.Open)
       {
          myConn.Close();
       }
    }

What I noticed is VERY similar to MySQLDriverCS .

    
20.08.2017 / 01:44