Connecting to MYSQL database error (UWP C#)

2019-09-09 22:07发布

问题:

I writing UWP app for windows 10 desktop

I trying to connect to DB on server

My code:

 using (MySqlConnection connection = new MySqlConnection("Database= milano_app2;Data Source=IP_OF_SERVER;User Id=USERNAME;Password=;SslMode=None;"))
        {
            connection.Open();


            MySqlCommand createCommand = new MySqlCommand("CREATE TABLE demotable(salary int,surname varchar(255))", connection);
            createCommand.ExecuteNonQuery();


            MySqlCommand addCommand = new MySqlCommand("INSERT INTO demotable (salary,surname) VALUES (1234,'Вейдер')", connection);
            addCommand.ExecuteNonQuery();

        }

But when I launch app i have this error

I think problem in encoding of BD?

How I can make it UTF-8?

Thank's for help.

回答1:

Add CharSet=utf8 to connection string :

"Database= milano_app2;Data Source=IP_OF_SERVER;User Id=USERNAME;Password=;SslMode=None;CharSet=utf8;"