c# - How do I set encoding in an NpgsqlConnection -
i have postgresql database, uses character encoding win1252
.
when querying database, records produce error when trying read data, because trying convert utf8
. happens on foreign names containing non-latin characters.
the error is:
error: 22p05: character byte sequence 0x81 in encoding "win1252" has no equivalent in encoding "utf8"
it happens when call read()
on npgsqldatareader
.
my connection defined as:
new npgsqlconnection("server=127.0.0.1;port=5432;database=xyz;user id=****;password=****;");
what can read data using c#?
i've managed solve problem. there no way of setting property in connection string or of properties of npgsqlconnection
or npgsqlcommand
.
however, able set value of client_encoding
in query. directly after opening connection first executed (non)query:
set client_encoding = 'win1252'
after that, subsequent command on same connection used proper encoding , returned results without complaints.
Comments
Post a Comment