none
reading non-English strings stored in varchar RRS feed

  • Question

  • We have Win32 legacy application. The database schema was designed long ago and it uses VARCHAR for strings. The app uses OLEDB/ADO for data access. We have some Arabic customers. As long as they created their databases with Arabic collation (i.e. Arabic_100_CI_AS), they can store Arabic strings as they are correctly handled through Win32/ADO data access layer. Now we are porting everything to C#. When we execute "select name from Table" in DataReader, Arabic strings are coming as sequences of question marks (i.e. "????"). I understand that, ideally, we should convert VARCHAR columns to NVARCHAR. Because of logistics and other issues this is not easy to do for us.

    I'd like to know if there is any way for C#/DataReader object to read correctly those Arabic strings that are currently stored in varchar columns? If old ADO/OLEDB could do that, I assume there must be a way of forcing correct Ansi-to-Unicode conversion when C# code retrieves data from SQL Server (?)I was thinking that as long as Regional settings of the operating system are configured to Arabic, the conversion of Arabic string from Ansi (stored in varchar column) to C#/Unicode string should happen transparently. So far it does not look like. I assume that I must be missing some point here - either operating system or/and SQL Server configuration or something related to executing DataReader.

    I'd appreciate any help.
    Thank you.


    software developer

    Friday, June 22, 2012 2:37 AM

Answers

  • I am not sure if this would help you.

    Thread.CurrentThread.CurrentCulture = 
    	new CultureInfo( "ar-SA", false );
    strData=Convert.ToString(dr["DbColumnName"],
    		 CultureInfo.CurrentCulture);
    Or
    CultureInfo myCIintl = 
    	new CultureInfo("ar-SA", false);
    strData=Convert.ToString(dr["DbColumnName"], 
    		myCIintl.CurrentCulture);


    Lingaraj Mishra

    Friday, June 22, 2012 5:40 AM

All replies

  • I am not sure if this would help you.

    Thread.CurrentThread.CurrentCulture = 
    	new CultureInfo( "ar-SA", false );
    strData=Convert.ToString(dr["DbColumnName"],
    		 CultureInfo.CurrentCulture);
    Or
    CultureInfo myCIintl = 
    	new CultureInfo("ar-SA", false);
    strData=Convert.ToString(dr["DbColumnName"], 
    		myCIintl.CurrentCulture);


    Lingaraj Mishra

    Friday, June 22, 2012 5:40 AM
  • Hi marek_m,

    Have you solved the issue? I look forward to hearing from you. If you need further help, please feel free to let me know.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, June 27, 2012 2:26 AM
    Moderator