0

I´m trying to write a programm with visual stuido and c#, to send querys to a mysql-database whiche I set up with xampp on windows7-64. I followed that tutorial:

https://ourcodeworld.com/articles/read/218/how-to-connect-to-mysql-with-c-sharp-winforms-and-xampp

my code

string query = "select * from testTbl";

        if(query == "")
        {
            MessageBox.Show("Please give me a query.");
            return;
        }

        string MySQLConnectionString = "server=localhost; port= 3306; user id=root;password=Password123;database=testDB;";

        MySqlConnection databaseConnection = new MySqlConnection(MySQLConnectionString);
        MySqlCommand commandDatabase = new MySqlCommand(query, databaseConnection);
        commandDatabase.CommandTimeout = 60;

        try
        {
            databaseConnection.Open();

            MySqlDataReader myReader = commandDatabase.ExecuteReader();

            if(myReader.HasRows)
            {
                MessageBox.Show("Result of query in Console.");

                while (myReader.Read())
                {
                    Console.WriteLine(myReader.GetString(0) + " - " + myReader.GetString(1) + " - " + myReader.GetString(2) + " - " + myReader.GetString(3));
                }

            }else
            {
                MessageBox.Show("Query transfer successful.");

            }

        }
        catch (Exception e)
        {

            MessageBox.Show("Query error: " + e.Message);
        }

I get an error: "localhost does not support ssl connection"

In the apache "httpd-ssl.conf" is that setting:

SSLEngine on

But it is only for port: 443 a virtual Host.

I changed the php.ini

safe_mode=On
safe_mode_gid=On

and found in websearche a hint to do following changes

mysqli.default_host = "127.0.0.1"
mysqli.default_port = "3306"
mysqli.default_user = "root"
mysqli.default_pw = "Password123"

with no effect to my problem.

If I duplicate the virtual host of port 443, change the port to 3306 and tell apache to listen on port 3306, my programm give me a different error:

"the reading of the stream has failed"

The debugger shows me, the databaseConnection.Open(); State ist "closed".

Im not sure if that is the right way. If yes, maybe the document root has to be changed? But I didn´t finde in my web searce how. But maybe I have to do some aditional changes to xampp. I hope anybody can help me with this.

Shadow
  • 33,525
  • 10
  • 51
  • 64
tewel
  • 11
  • 3
  • Try adding SslMode=none to your connection string--see https://stackoverflow.com/questions/45086283/mysql-data-mysqlclient-mysqlexception-the-host-localhost-does-not-support-ssl/45108611 – scotru Aug 04 '18 at 08:22
  • When you have a specific error message, then usually it is a lot faster to search for an answer than to ask a question... – Shadow Aug 04 '18 at 08:36
  • Thank you very much. I didn´t found that question and answere by searching. It works. – tewel Aug 04 '18 at 09:14

0 Answers0