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

Frank Martin 431 Reputation points
2022-02-05T07:38:39.123+00:00

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?

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,412 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,299 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Frank Martin 431 Reputation points
    2022-02-05T09:45:53.35+00:00

    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.

    0 comments No comments