0

I am using linq2db.postgresql to select data from a table the table includes some unicode in the description field.

        var dataContext = LinqToDB.DataProvider.PostgreSQL.PostgreSQLTools.CreateDataConnection(_ConnectionString, PostgreSQLVersion.v93);            
        var results = from p in dataContext.GetTable<Part>()                
                        select p;

        return results.ToList(); 

This throws an exception: 22021: invalid byte sequence for encoding "UTF8": 0xa3

Unfortunately the data is not mine and is what it is, and I need to select it out into a sql database.

Any ideas how to get around this? Or if I could configure linq2db to work with this that would be great and help welcome.

R Davies
  • 105
  • 1
  • 11
  • Similar question [here](https://stackoverflow.com/questions/4867272/invalid-byte-sequence-for-encoding-utf8). Is there invalid data or an encoding mixup perhaps? Could someone have stored data with the wrong encoding? – Panagiotis Kanavos Jul 06 '17 at 14:50
  • thanks, but the data is what it is and the database is not ours, I need to get the data out of there and this is the error. I can get the data out using PgSqlDataReader just was hoping to avoid the leg work for tables with 200+ columns – R Davies Jul 06 '17 at 14:54
  • Then use NpgSQL and EF, or another Dapper. Or find the actual encoding and configure LinqToDB to load the data using that encoding, not UTF8. It may be that LinqToDB used UTF8 by default, when another encoding is used – Panagiotis Kanavos Jul 06 '17 at 14:56
  • What do the data look like? `0xA3` is £ in ASCII. In UTF8 it's stored as 0xC2 0xA3. If the provider or database tried to load the character as UTF8 it would fail because no byte sequence starts with this character. – Panagiotis Kanavos Jul 06 '17 at 15:01
  • Best practice is change your PostgreSQL encoding same with LinqToDB – Adrian Hartanto Jul 06 '17 at 16:21
  • Check this link https://www.postgresql.org/message-id/55CA237A.4080300%40nqadmin.com, maybe it is your case –  Jul 06 '17 at 17:32

0 Answers0