NpgsqlConnection conn = new NpgsqlConnection(
"Server="+ConnectionInfo +";"+
"Port=5432;" +
"User Id=MyAdmin;" +
"Password=Test;" +
"Database=MyDB;"+
"Encoding = Unicode"
);
conn.Open();
Postgresql/npgsql cant write when useing danish letters
-
27-06-2022 - |
문제
I get this error when i try to write to my postgresql DB.
NpgsqlException: ERROR: 22021: invalid byte sequence for encoding "UTF8": 0xe5 0x27 0x2c
It only happen when i use danish letters (æ ø å).
Is there a way to set it to use ex. Unicode ?
I use Npgsql in a C# project.
I have no problem at all when iam not useing the danish letters.
해결책 3
다른 팁
Your app is buggy. It's sending latin-1 encoded strings as if they were utf-8.
The byte sequence in the error is the latin-1 for the string:
å',
per:
regress=> SELECT convert_from(BYTEA '\xe5272c', 'latin-1');
convert_from
--------------
å',
(1 row)
You must either set client_encoding
correctly to reflect the encoding of the text you're sending, or (preferably) use proper C# unicode strings when working with nPgSQL.
I had same problem when I do copy and paste from word document or notepad into my C# application textbox field. The simple solution is to add "Encoding = Unicode" into your postgresql connection string of your c# application. How simple could that be. I was relieved after going through three days of google search.