'Arabic characters showing as garbage in .Net when getting data from Sybase

I am trying to display Arabic characters from Sybase database using .Net Windows Forms application but they appear as garbage. I am using ODBC.

If I use ADO.Net then characters are displayed fine so the problem is only in ODBC (and OlEDB which I have also tried)

I tried to user CharSet=UTF8 in ODBC connection string but I started getting error Invalid character conversion. Here's my connecting string:

<add name="SybaseString" connectionString="DSN=myDatabase;UID=sa;PWD=sa123;CharSet=utf8" />

While displaying I am not doing anything fancy, just directly displaying data like this reader["ArabicName"].ToString()

There is no issue with how data is stored in database because when using ADO.Net it works fine. How do I fix this issue?



Solution 1:[1]

Ok using character set cp1256 in connection string fixed the issue. So final connection string would look like this:

<add name="SybaseString" connectionString="DSN=myDatabase;UID=sa;PWD=sa123;CharSet=cp1256" />

How I found out? First I ran this command sp_helpsort to find out character set used by the database. There I saw that the char set is cp1256 so I used the same and now it is working fine.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Frank Martin