Encoding=ASCII; and Encoding=UNICODE; do not work in an Npgsql 3 connection string

烈酒焚心 提交于 2019-12-12 02:12:04

问题


I have a new install of PostgreSQL (9.6.1) using the Big SQL installer, and a new install of Npgsql (3.2.0) using the .msi installer, but non-ASCII character support seems to be broken.

My connection string is:

<add name="Northwind" connectionString="Database=Northwind;Server=localhost;Port=5432;User Id=postgres;Password=123;Encoding=ASCII;" providerName="Npgsql"/>

I get exception messages like this, when reading back non-ASCII character data:

System.Text.DecoderFallbackException : Unable to translate bytes [C3] at index 22 from specified code page to Unicode.

I have tried using Encoding=UNICODE; instead, but neither works.


回答1:


You probably have an old Npgsql connection string. Encoding=ASCII or Encoding=UNICODE will no longer work when using current (3.2.0) Npgsql to access current (9.6.1) PostgreSQL.

Solution: just remove Encoding=xxx completely and everything works!

You don't need to 'fix' your Postgres encodings and locales, you don't need to try to find a working Encoding value to use in the connection string; Ngpsql 3 just works with no Encoding setting, against the default Postgres install settings on Windows (Encoding=UTF8 | Collate=English_United Kingdom.1252 | Ctype=English_United Kingdom.1252) (for UK, but I believe the same thing applies for English_United States.1252 for US, and other locales).

(See: https://github.com/npgsql/npgsql/issues/1396)



来源:https://stackoverflow.com/questions/42118301/encoding-ascii-and-encoding-unicode-do-not-work-in-an-npgsql-3-connection-stri

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!