Problem with Database Connection

-1

Could you help me figure out why you're giving this error?

Code:

using (_connection = new MySqlConnection("Database=test;Data Source=localhost;User Id=root;Password=teste;SslMode=None;"))
{
    _connection.Open();
    var cmd = new MySqlCommand("select name from user where id=1", _connection);
    using (var reader = cmd.ExecuteReader())
    {
        if (reader.Read())
        {
            textBlock.Text = (reader.GetString("name"));
        }
    }
}

    
asked by anonymous 09.03.2017 / 12:11

1 answer

0

Add the code below before opening the connection:

System.Text.EncodingProvider ppp;
ppp = System.Text.CodePagesEncodingProvider.Instance;
Encoding.RegisterProvider(ppp);

Response based in this answer .

    
09.03.2017 / 12:36