EF6 + Postgresql - 22021: invalid byte Sequence for encoding "UTF8": 0xc9 0x52

Asked

Viewed 629 times

7

I am trying to get data from a Postgresql database with Enconding SQL_ASCII, but in some records I get error message "22021: invalid byte Sequence for encoding "UTF8": 0xc9 0x52"

I have tried to set the Enconding in the connection string in several ways, but without success, error occurs "Keyword not supported"

Does anyone know of a solution other than switching the bank’s Enconding to UTF8?

  • 1

    What is the current encoding of the bank?

  • 1

    It is the Bank Trust is SQL_ASCII

  • 1

    The Provider I am using is the "Entityframework6.Npgsql -Version 3.0.7"

3 answers

6

In version 3.1.8 support for ClientEncoding in the connection string, which solves many problems: I already answered this here: Accentuation problem in postgresql with npgsql

The solution is:

var sqlBuilder = new NpgsqlConnectionStringBuilder
                {
                    Host = strLocal,
                    Database = strNome,
                    Username = strUser,
                    Password = strSenha,
                    Pooling = false,
                    Encoding = "windows-1252",
                    ClientEncoding = "sql-ascii"
                };

 string strConexao = sqlBuilder.ConnectionString;

Version log: https://github.com/npgsql/npgsql/milestone/36?closed=1

Log da Issue: https://github.com/npgsql/npgsql/issues/392

  • Finally these people had common sense and implemented it. It was just what was missing not being able to update the component because of the bank coding.

5


  • Support was added in version 3.1.8, I did tests with Entityframework and Dapper and it worked, but what you said about migrating to UTF-8 that is highly recommended is extremely valid, including this was told to me by the mantedores themselves.

1

Staff had the same problem using a bank sql_ascii with version 8.3 of Postgres. I resolved using the version 4.0.7 of Npsql and adding the parameters below in the connection string:

Host=localhost;Port=5432;Database=lab_sis;Username=labsis_usr;Password=******;***ENCODING=LATIN1;client Encoding=LATIN1***

Browser other questions tagged

You are not signed in. Login or sign up in order to post.