本文是小编为大家收集整理的关于在 "葡萄牙语 "数据库中无法用npgsql选择一些行的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。
问题描述
我有一个使用" SQL_ASCII"和模板" Template0"创建的PostgreSQL数据库.它在葡萄牙拥有数据,因此我有"não","feijão","avô"之类的数据.当我尝试检索具有此类字符的行时"〜^"它不起作用,否则可行.
错误:
- "错误解析第6列(sempresa = 0 -string)"}
- message ="不能转换为Unicode指定的代码页的索引0中的字节[C3]."
我正在使用npgsql和dapper
<packages> <package id="Dapper" version="1.50.2" targetFramework="net45" /> <package id="Npgsql" version="3.1.7" targetFramework="net45" /> </packages>
我搜索了很多,但没有任何可行.我尝试了:
在连接字符串中设置客户端编码:
var sqlBuilder = new NpgsqlConnectionStringBuilder { Host = host, Database = database, Username = user, Password = password, Pooling = false, ClientEncoding = "SQL_ASCII" // I also tried "UNICODE", "utf8", "win-1252" };
我还试图在选择
之前运行一个非Query命令以更改包含// I tried a lot of encondings: SQL_ASCII, win-1252, unicode connection.Execute("set client_encoding = 'SQL_ASCII'"); var data = connection.Query<T>(strSQL);
我无法更改编码数据库或重新创建数据库SINSE应用程序将在许多生产数据库中运行.
我希望没有人会提出这个问题,因为重复的罪过,我真的试图解决其他问题,但我发现没有什么可以奏效的.
推荐答案
我已经在NPGSQL中添加了对非UTF8编码的支持.这实际上只能在诸如此类的特殊边缘案例中使用,其中数据库是使用SQL_ASCII创建的,包含非ASCII字符,并且不可能进行编码更改.
我已经将此支持备份到下一个补丁版本3.1.8(似乎无害).目前,构建服务器有一些麻烦,但是如果您等待几天,则应在 http://myget.org/gallery/npgsql .请按照 https://github.com/npgsql/npgsql/npgsql/npgsql/sissues/392 /进度.
问题描述
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.
Errors:
- "Error parsing column 6 (sempresa=0 - String)"}
- Message = "Can not convert byte [C3] in index 0 of the code page specified for Unicode."
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 also tried to run a non-query command to change enconding before selecting
// 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.
推荐答案
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.
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.