0

I've got an oracle database which NLS_CHARACTERSET is AL32UTF8. I've got an application (ASP.NET C#) on a client which NLS_LANG is FRENCH_FRANCE.WE8MSWIN1252.

The accented characters are well displayed on the application. However, when there is an accented character in a WHERE clause, oracle doesn't find the data, although it's there.

I found that "é" was written in the database as "c3a9". This is done on the server (SqlDeveloper) so it works fine because there is no conversion yet between character sets. accented characters preview

However, in my application on the client, an SQL request with a clause WHERE which contains an accented character doesn't work. For exemple I have this request :

string request = "UPDATE fonction SET libelle = '" + new_libelle.Replace("'", "''") + "' WHERE libelle = '" + old_libelle.Replace("'", "''") + "'";

If there is an accented character in old_libelle, oracle doesn't find the data and so the update is not executed.

I cannot change the NLS_CHARACTERSET of the database because it's used by many other applications and I don't want side effects to appear.

How to fix this?

Mat
  • 202,337
  • 40
  • 393
  • 406
Sebriniel
  • 171
  • 2
  • 13

1 Answers1

0

Check the encoding settings in your web environment, e.g. Response.ContentEncoding and/or Response.Charset

If you set NLS_LANG=FRENCH_FRANCE.WE8MSWIN1252 then you must set these values Encoding.WindowsCodePage (which should be CP-1252 in your case)

Otherwise, if you prefer Unicode, (most likely UTF-8) then set your NLS_LANG accordingly to FRENCH_FRANCE.AL32UTF8

Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110
  • In the web environment, the charset is 'utf-8'. I don't know how to set NLS_LANG directly in my application, can you explain a little more please? I can't change the NLS_LANG of the client because there are several other applications runing on it. – Sebriniel Mar 25 '19 at 10:30
  • In the command line when you start your application add `SET NLS_LANG=FRENCH_FRANCE.AL32UTF8` at the beginning, then it should be fine. Or use the ODP.NET Managed Driver (`Oracle.ManagedDataAccess.Client`) which is not `NLS_LANG` sensitive. – Wernfried Domscheit Mar 25 '19 at 10:44
  • But this is to do every time the application is run isn't it? My application will be used by users that are not used with coding, and it's not convenient for them to run a command line in order to make the application work. – Sebriniel Mar 25 '19 at 10:51
  • If you cannot set `NLS_LANG` for entire machine nor for the process then there is no other way than using the ODP.NET Managed Driver. – Wernfried Domscheit Mar 25 '19 at 11:53
  • I think I'm not far from using this driver. This is what I have : `conDB = new OracleConnection(System.Configuration.ConfigurationManager.ConnectionStrings["oraclecs"].ToString());` `` – Sebriniel Mar 25 '19 at 13:17