invalid byte sequence for encoding

invalid byte sequence for encoding

Postby colomboz » Mon 15 Sep 2008 09:14

Hello,
i'm using PostresSQLDirect for .NET2 and I've some problems with encoding.

Following a code sample witch causes the exception (the exception thrown is always the same “invalid byte sequence for encoding "UTF8": 0xe0a020”) :

Code: Select all
using (CoreLab.PostgreSql.PgSqlConnection cnn = new CoreLab.PostgreSql.PgSqlConnection())
            {
cnn.ConnectionString = @"User Id=sim;Host=localhost;Database=sim;Character Set=UTF8;Persist Security Info=True;Schema=gsim;password=sim";
                cnn.Charset = "UTF8";
                cnn.Open();
                CoreLab.PostgreSql.PgSqlCommand cmd = new CoreLab.PostgreSql.PgSqlCommand();
                cmd.Connection = cnn;
                cmd.CommandText = "INSERT INTO gsim.area_produttiva (nome) VALUES (:nome)";
                CoreLab.PostgreSql.PgSqlParameter p = new CoreLab.PostgreSql.PgSqlParameter();
                p.ParameterName = "nome";
                p.Value = "provà"; // <-- The problem is about "à" char
                p.PgSqlType = CoreLab.PostgreSql.PgSqlType.VarChar;

                cmd.Parameters.Add(p);
                cmd.ExecuteNonQuery();
                cnn.Close();
            }




Db creating script:

CREATE DATABASE sim
WITH OWNER = sim
ENCODING = 'UTF8';


Thanks.
colomboz
 
Posts: 1
Joined: Mon 15 Sep 2008 08:56

Postby Shalex » Wed 17 Sep 2008 07:27

We recommend to set Unicode=true instead of Charset = "UTF8".

Code: Select all
using (CoreLab.PostgreSql.PgSqlConnection cnn = new CoreLab.PostgreSql.PgSqlConnection())
{
cnn.ConnectionString = @"User Id=sim;Host=localhost;Database=sim;Persist Security Info=True;Schema=gsim;password=sim";
cnn.Unicode = true;
cnn.Open();
CoreLab.PostgreSql.PgSqlCommand cmd = new CoreLab.PostgreSql.PgSqlCommand();
cmd.Connection = cnn;
cmd.CommandText = "INSERT INTO public.area_produttiva (nome) VALUES (:nome)";
CoreLab.PostgreSql.PgSqlParameter p = new CoreLab.PostgreSql.PgSqlParameter();
p.ParameterName = "nome";
p.Value = "provàè°"; // <-- there is no problem with "àè°" chars
p.PgSqlType = CoreLab.PostgreSql.PgSqlType.VarChar;
cmd.Parameters.Add(p);
cmd.ExecuteNonQuery();
cnn.Close();
}
Shalex
Devart Team
 
Posts: 7793
Joined: Thu 14 Aug 2008 12:44


Return to dotConnect for PostgreSQL