本文介绍了编码= ASCII;和Encoding = UNICODE;在Npgsql 3连接字符串中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Big SQL安装程序重新安装了PostgreSQL(9.6.1),并使用.msi安装程序重新安装了Npgsql(3.2.0),但是似乎不支持非ASCII字符。 / p>

我的连接字符串为:

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

当回读非ASCII字符数据时,我得到如下异常消息:

  System.Text.DecoderFallbackException:无法将索引22处的字节[C3]从指定的代码页转换为Unicode。 

我尝试使用 Encoding = UNICODE;

解决方案

您可能使用了旧的Npgsql连接字符串。使用当前(3.2.0)Npgsql访问当前的()时 Encoding = ASCII Encoding = UNICODE 将不再起作用9.6.1)PostgreSQL。



解决方案:只需完全删除 Encoding = xxx ,一切正常!



您无需修复您的Postgres编码和语言环境,无需尝试查找有效的编码在连接字符串中使用的值; Ngpsql 3只能在没有 Encoding 设置的情况下使用,而与Windows上的默认Postgres安装设置( Encoding = UTF8 | Collat​​e = English_United Kingdom.1252 | Ctype = English_United Kingdom.1252 )(适用于英国,但我认为, English_United States.1252 适用于美国及其他地区)。



(请参阅:)


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.

解决方案

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)

这篇关于编码= ASCII;和Encoding = UNICODE;在Npgsql 3连接字符串中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 11:39