windows - 编码=ASCII;和编码= UNICODE;不要在 Npgsql 3 连接字符串中工作

标签 windows postgresql utf-8 npgsql

我使用 Big SQL 安装程序新安装了 PostgreSQL (9.6.1),使用 .msi 安装程序安装了新的 Npgsql (3.2.0),但非 ASCII 字符支持似乎已损坏。

我的连接字符串是:

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

当读回非 ASCII 字符数据时,我收到这样的异常消息:

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

我试过使用 Encoding=UNICODE; 代替,但都不起作用。

最佳答案

您可能有一个旧的 Npgsql 连接字符串。当使用当前 (3.2.0) Npgsql 访问当前 (9.6.1) PostgreSQL 时,Encoding=ASCIIEncoding=UNICODE 将不再有效。

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

您不需要“修复”您的 Postgres 编码和语言环境,您不需要尝试找到一个有效的 Encoding 值以在连接字符串中使用; Ngpsql 3 仅在没有 Encoding 设置的情况下工作,与 Windows 上的默认 Postgres 安装设置相反(Encoding=UTF8 | Collat​​e=English_United Kingdom.1252 | Ctype=English_United Kingdom.1252) (对于英国,但我相信同样的事情适用于美国和其他地区的 English_United States.1252)。

(参见:https://github.com/npgsql/npgsql/issues/1396)

关于windows - 编码=ASCII;和编码= UNICODE;不要在 Npgsql 3 连接字符串中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42118301/

相关文章:

php - 从 web 服务向 mysql 数据库插入数据时瑞典字符编码失败

php.ini 不允许我禁用_functions

c++ - 显示可变消息的自定义异常,不同编译器中的不同行为

python - 如何制作一个可以注销、关机和重启计算机的python脚本?

postgresql - PostgreSQL 中的短语比较

postgresql - PostgreSQL 的 CLUSTER 与 SQL Server 中的聚集索引有何不同?

php - UTF8 到 php 中的等效数字

php - 在 Linux 服务器上通过 PHP 执行 Windows 程序

ruby-on-rails - PG::InsufficientPrivilege at/ERROR:关系 schema_migrations 的权限被拒绝

java - 无法使用java在Windows服务器中保存utf8文件