2

I am assigning Urdu text to a variable in c# and inserting it into database (SendMessages table), it saves Urdu message perfectly without any modification, great but when that message is received in any mobile handset then it appears as ??????????????????????, why ? i checked it with all urdu compatible handsets which receive other urdu messages perfectly but not this one.

Code asp.net:

String MessageLanguage= Convert.ToString(ViewState["LanguageCode"]); //

                        if (MessageLanguage == "ur")
                        {
                            String UrduMsg = ComplaintCode +" "+"اپکی سثیکایت درج کردی گیؑ ھے۔ سثیکایت کوڈ یہ ہے";
                            quebiz.Insert(lblContact.Text, UrduMsg, null, Convert.ToInt32(lblComplainantID.Text), null, null);
                            ViewState["LanguageCode"] = null;

                        }

In simple words, urdu message being passed from C# into sql table is fine and perfect, not problem but after receiving same sms in handset, it doesn't work that way.

why ? help ? I am using asp.net C#.net 4.0 with sql server 2014.

John Nash
  • 155
  • 1
  • 4
  • 12
  • This sounds like an encoding error. do you have this problem just with Urdu, or do you run into it with other alphabets as well, like Arabic, Eastern Kanji, Hindu,...? – Nzall Sep 08 '14 at 09:20
  • every languae except english – John Nash Sep 08 '14 at 09:31
  • I'm not 100% sure, but it looks like your ComplaintCode is encoded in ASCII, which can only display Latin characters properly. Because of this, your UrduMsg is also in ASCII. Those Urdu messages that work, are you also concatenating those with another string? – Nzall Sep 08 '14 at 09:41
  • EDIT: that's your problem. varchar does not support non-Latin characters. try changing that to nvarchar. – Nzall Sep 08 '14 at 09:53
  • ok wait lemme change but why does sql records shows exact message, in urdu but not mobile, at first it should have created problem at db level – John Nash Sep 08 '14 at 09:57
  • I'm not sure, but I think it's because your SQL management studio accounts for this and displays it properly. However, your program does not use SQL Management Studio and accesses the database directly, using the encoding of the field. I'm not sure though, and it might be a completely different reason why SQLMS shows it properly. – Nzall Sep 08 '14 at 10:00
  • i changed complaint code to nvarchar plus i tried sending without concatenating with complaintcode but not worked, same problem – John Nash Sep 08 '14 at 10:05
  • Then it's possible your project encoding in Visual Studio is not set properly. check http://stackoverflow.com/questions/840065/how-to-change-source-file-encoding-in-csharp-project-visual-studio-msbuild-ma for more info. – Nzall Sep 08 '14 at 10:07
  • i did, it's already in Unicode(8) codepage 65001 format – John Nash Sep 08 '14 at 10:14

2 Answers2

0

According to your comments, you're using varchar to store the message in your database. However, varchar does not support Unicode, which means that anything that's not Latin characters (the characters used by English) does not show properly. Change that to nvarchar, which does support Unicode.

Nzall
  • 3,439
  • 5
  • 29
  • 59
0

An idea could be use varchar in your database and follow the steps

  1. Use base 64 to save the data into data base
  2. Use Encoding.UTF8 to get bytes and convert them to Base64
  3. When fetch data from database use Encoding.UTF8.GetString(Convert.FromBase64String("value") and use this value to display.
शेखर
  • 17,412
  • 13
  • 61
  • 117