views:

45

answers:

2

I tried to store Arabic string in SQL 2008 database but it converted to " question mark " why ? and what should I do ?

A: 

In case of Oracle, I can tell you that it is required to setup the database in AL32UTF8 format. So that data gets stored in multibytes. While retrieving that data, locale needs to be set properly to view data in the proper format. In your case, probably database is not in UTF8 format? Once you verify that, make sure your locale is set properly to view that data. Probably get a hex dump of the string you are storing and also get the same hex dump from the database table. Compare the hex values and if they are same, you know that data is going into database properly, its just the locale needs to be set properly at the client side to view the data.

Shamik
when I open SQL server 2008 and edit table to enter Arabic string after I press enter it convert it to "question mark " if the UTF8 format is the problem how can I make it UTF8
salamonti
do you know the hex value of the arbic character that you stored? That way it will be easy to find out whether it is the database issue or client issue?
Shamik
+2  A: 

You need to choose an Arabic collation for your varchar/char columns or use Unicode (nchar/nvarchar)

CREATE TABLE #test
(
col1 VARCHAR(100) COLLATE Latin1_General_100_CI_AI,
col2 VARCHAR(100) COLLATE Arabic_CI_AI_KS_WS,
col3 NVARCHAR(100)
)
INSERT INTO #test VALUES(N'لا أتكلم العربية',N'لا أتكلم العربية',N'لا أتكلم العربية')

SELECT * FROM #test

Returns

col1                           col2                           col3
------------------------------ ------------------------------ ------------------------------
?? ????? ???????               لا أتكلم العربية               لا أتكلم العربية

To see a list of Arabic collations use

SELECT name, description 
FROM fn_helpcollations() 
WHERE name LIKE 'Arabic%'
Martin Smith
thank you so so so much
salamonti