问题描述
我有一个使用 SQL_ASCII和模板 template0创建的postgresql数据库。它以葡萄牙语保存数据,因此我拥有诸如Não,Feijão,Avô之类的数据。当我尝试检索具有此类字符〜^的行时,它将不起作用,否则它将起作用。
I have a postgresql database that was created with "SQL_ASCII" and template "template0". It holds data in Portuguese so I have data such as "Não", "Feijão", "Avô". When I try to retrieve rows that have these kind of characters "~^" it does not work, otherwise it works.
错误:
- 解析列6时出错(sempresa = 0-字符串)}
- 消息=无法转换字节[C3]为Unicode指定的代码页的索引0。
我正在使用Npgsql和Dapper
I'm using Npgsql and Dapper
<packages>
<package id="Dapper" version="1.50.2" targetFramework="net45" />
<package id="Npgsql" version="3.1.7" targetFramework="net45" />
</packages>
我搜索了很多,但是没有用。我尝试过:
I searched a lot but nothing works. I've tried:
在连接字符串中设置客户端编码:
Setting up client encoding in connection string:
var sqlBuilder = new NpgsqlConnectionStringBuilder
{
Host = host,
Database = database,
Username = user,
Password = password,
Pooling = false,
ClientEncoding = "SQL_ASCII"
// I also tried "UNICODE", "utf8", "win-1252"
};
我还试图在选择
// I tried a lot of encondings: SQL_ASCII, win-1252, unicode
connection.Execute("set client_encoding = 'SQL_ASCII'");
var data = connection.Query<T>(strSQL);
我无法更改数据库编码或重新创建数据库,因为应用程序将针对大量生产数据库运行。
I CANNOT change database encoding or recreate database sinse the application will run against lots of production databases.
我希望没有人将此问题标记为重复的罪过,但我确实尝试用其他问题解决,但我发现没有任何作用。
I hope nobody flags this question as duplicated sinse I really tried to solve with other questions but nothing I found worked.
推荐答案
我在Npgsql中添加了对非UTF8编码的支持。实际上,只有在这样的特殊情况下才应使用此方法,在这种情况下,数据库是使用SQL_ASCII创建的,包含非ASCII字符,并且无法更改编码。
I've added support for non-UTF8 encodings to Npgsql. This should really be used only in special edge cases such as this, where the database was created with SQL_ASCII, contains non-ASCII characters, and an encoding change is impossible.
我已经将此支持反向移植到了下一补丁版本3.1.8(似乎已经足够无害了)。目前,构建服务器存在一些问题,但是如果您等了几天,您应该可以在。关注了解更多更新/进度。
I've backported this support to the next patch version, 3.1.8 (seems harmless enough). There's some trouble with the build server at the moment, but if you wait a few days you should have a CI package of 3.1.8 available with the new support at http://myget.org/gallery/npgsql. Follow https://github.com/npgsql/npgsql/issues/392 for more updates/progress.
这篇关于无法使用npgsql在“葡萄牙语”上选择某些行。数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!