Problem saving accent with Entity Framework and PostgreSQL

1

I need to migrate a system with SQLSERVER database to a PostGreSQL 9.3. I have never worked with PostGre before so I'm using Entity Framework 6 with model-first to make the process easier. The migration application is being developed in WPF. My first two tables imported quietly, but one of the records in the third table needs to be inserted " NOT ".

IMPORTANT: I do not have the option to insert without an accent because the system that uses the base of POSTGre is a legacy system that will only understand with an accent. On a production basis of this system is accented and with the same configuration in the image below.

 // produtor rural
 if (objPessoa.pes_cliProdutorRural == true)
       objNovoCliente.produtorrural = "SIM";
 else
       objNovoCliente.produtorrural = "NÃO";

  // adicionar no contexto
  this.objCtxMSP2.tbcadclientes.Add(objNovoCliente);
  this.objCtxMSP2.SaveChanges();

But it gives the following error in SaveChanges:

  

InnerException = {"ERROR: 22001: too long value for type   character (3) "}

Searching the internet I saw that it could be something about "collation" and / or "encoding".

This is the current bank configuration:

WhentryingtocreatethebankwithencodingLATIN1asviinanotherforumgivesthefollowingerror

Any ideas how to solve this?

    
asked by anonymous 28.06.2016 / 22:23

3 answers

0

I recently had another problem with postgresql and npgsql, but this time I posted on stackoverflow in English, getting in touch with the responsible staff, and they will release an update that should also solve this problem, which is pretty much the same. The fix will be in version 3.1.8 of npgsql.

link

    
25.08.2016 / 22:50
3

It is likely that your IIS environment is in UTF8 and you are trying to use latin1 (which is compatible only with windows-1252 and iso-8859-1).

If you use Latin1, you can configure web.config like this:

<system.web>
     ...
     <globalization
         requestEncoding="iso-8859-1"
         responseEncoding="iso-8859-1"
         fileEncoding="iso-8859-1"
         culture="pt-BR"
         uiCulture="pt-BR" />
     ...
</system.web>

If you decide to migrate the database to utf8 (or you are already using it) then use:

<system.web>
     ...
     <globalization
         requestEncoding="utf-8"
         responseEncoding="utf-8"
         fileEncoding="utf-8"
         culture="pt-BR"
         uiCulture="pt-BR" />
     ...
</system.web>
  

The ... are just to say that it's anywhere in the XML, do not copy them.

    
29.06.2016 / 03:20
0

If it is possible to set your Entity in WebConfig or its OnModelCreating set the creation of the bank in a form that satisfies this statement:

CREATE DATABASE nome_banco WITH OWNER = usuario_banco ENCODING = 'LATIN1' TABLESPACE = pg_default LC_COLLATE = 'C' LC_CTYPE = 'C' CONNECTION LIMIT = -1 TEMPLATE template0;
    
29.06.2016 / 02:55