I have this problem reading "character varying" field data through a C# program from a PostgreSQL version 12 database table using npgsql. This is the code I use:
NpgsqlDataSource DataSource = NpgsqlDataSource.Create(connectionString);
NpgsqlCommand command = DataSource.CreateCommand("SET client_encoding = 'UTF8'");
command.ExecuteNonQuery();
command = DataSource.CreateCommand(this.Config.PostgreSQL_CommandString);
int righe= command.ExecuteNonQuery();
NpgsqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
var v = reader.GetValue(1);
}
The field contains, for example, the value ""Stanley Kubrick"" and what is read by the program (v variable) is "1\0\0\0\u00042\0\0\0\u0004T\0\0\0p".
I have already tried modifying the encode/decode and installing the latest versions of the dlls, but the result does not change. I would expect to be able to read the data correctly in readable format.
Do you have any suggestions? Thanks
;Client Encoding=UTF8)? if the provider doesn't know that you've changed the encoding, it could do incorrect things