Retrieving malformed string when containing accented words

1

In my application I'm having trouble fetching the data in the PostgreSQL database, accented words being retrieved from the database and dealing with DataReader are coming poorly formatted as in the image below.

  • In the correct formatted database

  • BeingreadinDataReader

The Encoding of the bank is in UTF8 and the Character type is Portuguese_Brazil.1252 if it helps.

I'm reading the data as follows:

var command = new NpgsqlCommand("Select * from Empresa", con);
con.Open();
NpgsqlDataReader dr = command.ExecuteReader();
while (dr.Read())
{
     Empresa e = new Empresa();
     e.IdEmpresa = Convert.ToInt32(dr["id_empresa"]);
     e.NomeFantasia = dr["nome_fantasia"].ToString();
}

Here is the image to better demonstrate the language that my database is:

    
asked by anonymous 03.11.2014 / 22:01

1 answer

2

Solved, in my ConnectionString I gave a different Encoding as follows.

  • Before:

    Server=127.0.0.1;User Id=postgres; Password=123;Database=gemax;
    
  • Then:

    Server=127.0.0.1;User Id=postgres; Password=123;Database=gemax; Encoding=UNICODE;
    

According to the Mono-Project documentation, if there is a problem with UTF-8 accents, recommend using UNICODE.

    
04.11.2014 / 14:46