1

i added a function that returns a value from oracle database with Arabic character set, but when i run my program the value show up in textbox is with chinese or japanese character like this

"敔瑸潂x"

.The value to be returned is Arabic character. I tried to change the textbox to right to left, but it doesn't help. I tried to change the stored value to english but the same character is returning .

any suggestion please ?

public void Get_Desc()
{
    string oradb = "Data Source=schema;User Id=user;Password=pwd;";

    string CommandStr = "F_Get_Office_Desc";

    using (OracleConnection conn = new OracleConnection(oradb))
    using (OracleCommand cmd = new OracleCommand(CommandStr, conn))
    {
        cmd.CommandType = CommandType.StoredProcedure;

        cmd.Parameters.Add("iCode", OracleDbType.Varchar2).Value = Current_code;
        cmd.Parameters.Add("oDesc", OracleDbType.Varchar2, 4).Direction = ParameterDirection.ReturnValue;                
        conn.Open();
        cmd.ExecuteNonQuery();

        Current_Desc.Text = cmd.Parameters["oDesc"].Value.ToString();
    }
}
VVN
  • 1,607
  • 2
  • 16
  • 25
samer
  • 193
  • 5
  • 21
  • 1
    You are using the wrong column type ,`VARCHAR2` can't represent arabic, make sure its `NVARCHAR2`. – Xi Sigma Mar 01 '16 at 01:31
  • 1
    When your characterset of the database is `AL32UTF8` (or similar) then `VARCHAR2` can represent arabic characters. – Wernfried Domscheit Mar 01 '16 at 06:48
  • 1
    What is the value of your Environment Variable `NLS_LANG`? If it is not set, what is the value your your registry key `HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\KEY_{Oracle-Home}\NLS_LANG`, resp. `HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ORACLE\KEY_{Oracle-Home}\NLS_LANG`? – Wernfried Domscheit Mar 01 '16 at 06:51
  • @decoherence, no this returns the **database** character set! I asked for the **client** character set. See http://stackoverflow.com/questions/33783902/odbcconnection-returning-chinese-characters-as/33790600#33790600 to understand the difference. – Wernfried Domscheit Mar 01 '16 at 07:32
  • Which provider do you use for the OracleConnection? – Wernfried Domscheit Mar 01 '16 at 08:12
  • the NVARCHAR2 suggestion do not work and the NLS_LANG IS AMERICAN_AMERICA.AR8MSWIN1256 I am using using Oracle.DataAccess.Client as oracle connection provider – samer Mar 01 '16 at 14:56
  • by the way the arabic are shown correctly when I query data using toad or sql developers – samer Mar 01 '16 at 14:56

1 Answers1

0

Strange, usually Oracle.DataAccess.Client inherits the NLS_LANG value. Which value did you read? Perhaps you read the 32-Bit value but the application is running on 64-Bit.

Try to create an environment variable NLS_LANG=AMERICAN_AMERICA.AR8MSWIN1256 since the environment value takes precedence over all other settings.

Try also NLS_LANG=AMERICAN_AMERICA.AL32UTF8.

In your code add

Console.WriteLine(conn.GetSessionInfo().ClientCharacterSet);

after you open the connection. What is the output?

Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110
  • actually as I comment before I am using environment variable AMERICAN_AMERICA.AR8MSWIN1256 and i got this as u ask for AR8MSWIN1256.. umm i will try my application on other machine working under 32bit OS .. btw if the 64bit work on 32bit OS then will change my project to 64bit if that solve my problem – samer Mar 02 '16 at 23:30
  • What is your database character set? Did you also try `NLS_LANG=AMERICAN_AMERICA.AL32UTF8`? What do you get when you select the values with `SELECT DUMP(F_Get_Office_Desc(...)) FROM dual;` – Wernfried Domscheit Mar 03 '16 at 07:16