Solved

View Arabic characters under SQL Express Edition

Posted on 2009-07-09
32
917 Views
Last Modified: 2012-05-07
Hi,
I have designed a database over mySQL that contains Arabic characters using UTF8 encoding.

However, I decided to migrate my data from mySQL to SQL Server Express edition and I was able to import some tables from mySQL to SQL Server.

The problem is that when I display my query under SQL Server I cannot view the Arabic characters.

What should I do in my query in order to display the Arabic characters?

Thank you
0
Comment
Question by:cooldude87801
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 17
  • 14
32 Comments
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24811467
Make sure that the columns in SQL Server 2005 are set to Nchar/ Nvarchar so that it can store it as Arabic characters.

In MySQL, UTF8 coding is set at database level and once you enable it you will be able to store Arabic characters.

In SQL Server, you have to create Nchar/ NVarchar to store unicode ( Arabic) characters.

And while inserting records into SQL Server table for those Nchar / NVarchar columns make sure that your Prefix it with N'abc' assuming abc are arabic characters.

If not then it will convert it to some other characters and you will not be able to see it properly.
0
 

Author Comment

by:cooldude87801
ID: 24811597
Hi,
Thank you for your quick response.

I have used the following link in importing tables from mysql to SQL Server 2008

http://www.codeproject.com/KB/database/migrate-mysql-to-mssql.aspx

This method imported all the tables from mysql to mssql.  How can I modify it so I can add the N prefix?

0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24811683
During this particular Step:

SELECT * INTO testMySQL.dbo.shoutbox
FROM openquery(MYSQL, 'SELECT * FROM tigerdb.shoutbox')

Make sure that the necessary columns in SQL Server table are of Datatype Nchar/ Nvarchar otherwise your Unicode characters are lost at this point of time.
0
Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

 

Author Comment

by:cooldude87801
ID: 24811779
the columns have nvarchar data type but still I cannot view the data.
0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24811805
Do you have Arabic Language pack installed in your system so that it will display those characters properly.

Kindly tell me whether you are using SSMS or any application to view the data
0
 

Author Comment

by:cooldude87801
ID: 24811926
I am using SSMS to view the data...also, I do have the Arabic Language pack installed.

I can view the Arabic data under mysql through Phpmyadmin by changing the browser encoding to utf8 so I have no problem with viewing Arabic on my PC
0
 

Author Comment

by:cooldude87801
ID: 24811999
There are several collations for Arabic under SSMS ...which one should I choose to view UTF8?
0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24812531
Kindly use the below query:

SELECT * FROM fn_helpcollations()
WHERE description LIKE 'Arabic%'

Kindly use this as a guideline for selecting your collation type:

http://msdn.microsoft.com/en-us/library/ms143515.aspx
0
 

Author Comment

by:cooldude87801
ID: 24812581
Hi rrjeqan
I am going to try the collations until I find the one that can display the Arabic text.

However, my question is, can SQL Server display Arabic data encoded in UTF8?

0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24814369
>> However, my question is, can SQL Server display Arabic data encoded in UTF8?

Yes. 100%
UTF-8 (8-bit UCS/Unicode Transformation Format) is a variable-length character encoding for Unicode / International Characters other than English.

In databases like MySQL, DB2 this is handled at the database level and server handles Unicode characters in its String columns.

In SQL Server, you need to set it at column level ( By Default all databases supports it) by creating that as a Nchar / Nvarchar column. And you need to handle / differentiate those strings by prefixing N before the values when you pass within ''.

Hope this clarifies.
0
 

Author Comment

by:cooldude87801
ID: 24814933
it seems the query that I am using is not helping

SELECT * INTO testMySQL.dbo.shoutbox
FROM openquery(MYSQL, 'SELECT * FROM tigerdb.shoutbox')

because I am not building the table and I cannot insert N before the values.

Do you have another query where I can read the data from mySQL and insert it into SSMS prefixed by N?

Thank you for your time and effort in debugging this problem
0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24815800
Just make sure that you have those columns with datatype as nchar/ nvarchar in the table testMySQL.dbo.shoutbox.
SELECT statement doesn't have any issues and will work fine as expected if you have those datatypes properly.

Prefixing N is required if you do an insert statement like this:

insert into ur_table ( a, b, c )
values ( 1, 'ab', N'abc')

Assuming column c is of datatype Nchar/ nvarchar, this should help you out.
0
 

Author Comment

by:cooldude87801
ID: 24815897
I am not building the table, I am using this query to build the table on the fly that's why I don't choose the datatype of the column.

But when I look at the columns after being created..I see that they have nvarchar as data type yet still the data doesn't show.

I still didn't find the collation that relates to UTF8


0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24816223
If you have Language packs installed earlier, then can you create a temp table and test it out:

create table test ( a int identity, b nvarchar(10));
insert into test (b) values ( N'abc');

Replace abc with your arabic characters and give it a try.
If its successful, then its a problem with your current migration. Otherwise we can nail it down
0
 

Author Comment

by:cooldude87801
ID: 24816727
I tried it out ...and I can view the Arabic characters very clear....

I am really puzzled???
0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24819947
>> I tried it out ...and I can view the Arabic characters very clear....

I am confident on the approach mentioned above and I am actually puzzled why it didn't worked for you.

Then we can come to a conclusion that there was some problems in the migration process..

This is where your problem arises.

SELECT * INTO testMySQL.dbo.shoutbox
FROM openquery(MYSQL, 'SELECT * FROM tigerdb.shoutbox')

Instead of *, just mention your column names and then cast those columns to nchar/ nvarchar in the below part.

'SELECT * FROM tigerdb.shoutbox'

Kindly give it a try.
0
 

Author Comment

by:cooldude87801
ID: 24821225
Here is the query I used to for inserting the customer First Name and Last name into SSMS DB.

SELECT * INTO GoldenBrown7.dbo.customer
FROM openquery(MYSQL, 'SELECT N(CUSTOMFNAME), N(CUSTOMLNAME) FROM gbdb.customer')

However, I am getting error messages about casting CUSTOMFNAME and CUSTOMLNAME with N..

something wrong with the syntax....to make sure the query is correct I removed N and I executed the above query and it went fine but the Arabic data didn't show up

How can I cast the above column names correctly?

Thank you for your help

0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24821268
I meant this one:

SELECT cast(CUSTOMFNAME AS nvarchar(1000)), cast(CUSTOMLNAME AS nvarchar(1000)) INTO GoldenBrown7.dbo.customer
FROM openquery(MYSQL, 'SELECT CUSTOMFNAME, CUSTOMLNAME FROM gbdb.customer')
0
 

Author Comment

by:cooldude87801
ID: 24821578
Hi again,
I am getting the following error from executing your query

Msg 1038, Level 15, State 5, Line 1
An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Change the alias to a valid name.
Msg 1038, Level 15, State 5, Line 1
An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Change the alias to a valid name.


however, when I remove the cast ....it executes correctly....but no good data
0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24821649
My mistake.. Try this one out

SELECT cast(CUSTOMFNAME AS nvarchar(1000)) CUSTOMFNAME, cast(CUSTOMLNAME AS nvarchar(1000)) CUSTOMLNAME INTO GoldenBrown7.dbo.customer
FROM openquery(MYSQL, 'SELECT CUSTOMFNAME, CUSTOMLNAME FROM gbdb.customer')
0
 

Author Comment

by:cooldude87801
ID: 24821712
I tried the query and it executed correctly ....but the data is still not viewable!!

I don't think the problem with the data type.

I can see the column data type is nvarchar 1000
0
 

Author Comment

by:cooldude87801
ID: 24821742
I am using the following collation  Arabic_CS_AS

I have a hunch that the problem is with the collation ....but I don't know which collation should I use
0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24821758
Kindly use this collation Arabic_CI_AI_WS and give it a try..
0
 

Author Comment

by:cooldude87801
ID: 24821809
I created a new database and selected the collation you gave me ....but still no luck!!!!!

by the way, how can you alter the collation in an existed table without rebuilding it again?
0
 

Author Comment

by:cooldude87801
ID: 24822004
I executed this query

SELECT CUSTOMFNAME , CUSTOMLNAME FROM openquery(MYSQL, 'SELECT CUSTOMFNAME, CUSTOMLNAME FROM gbdb.customer')

just to view the data from mySQL and I am still cannot view the data..could that be because of mySQL encoding?

I am wondering !!
0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24822159
>> just to view the data from mySQL and I am still cannot view the data..could that be because of mySQL encoding?

Then you lost your Unicode values in MySQL itself I guess.
And we tried importing values ( which are not actually unicode) to nchar/ nvarchar table.

Haven't thought of this one as you mentioned that unicode characters were there in MySQL.

So what's the plan now..
0
 

Author Comment

by:cooldude87801
ID: 24823069
I am not sure that i understood your reply.

I can still view the data under mysql through phpmyadmin on the localhost and I can view it also online.

So how did I loose the Unicode value?

The data type that I am using under mySQL is utf8_general_ci

I am still questioning the ability of SSMS to display UTF8



0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24823286
>> just to view the data from mySQL and I am still cannot view the data..could that be because of mySQL encoding?

These words confused me.. So ignore my previous comment.

>> I am still questioning the ability of SSMS to display UTF8

Yes.. SSMS has the ability to display UTF8 characters which was proven in the earlier test table creation and insert right.

Kindly try this one out to see whether it displays properly or not.

SELECT CUSTOMFNAME , CUSTOMLNAME FROM openquery(MYSQL, 'SELECT cast(CUSTOMFNAME as nvarchar(1000)) CUSTOMFNAME, cast(CUSTOMLNAME as nvarchar(1000)) CUSTOMLNAME FROM gbdb.customer')
0
 

Author Comment

by:cooldude87801
ID: 24823508
I tried it out but it is not working:

Cannot get the column information from OLE DB provider "MSDASQL" for linked server "MYSQL".

it would work fine without the cast.

my doubt was about reading en encoded data by another database
0
 

Author Comment

by:cooldude87801
ID: 24829279
Dear rrjegan17
I hope you are not raising the white flag!
0
 
LVL 57

Accepted Solution

by:
Raja Jegan R earned 500 total points
ID: 24833635
>> I hope you are not raising the white flag!

Not sure what you meant here. When you insert records from a UNICODE table, you will have unicode information stored properly. A proof below.

http://blogs.msdn.com/mssqlisv/archive/2006/07/07/659374.aspx

Or Else use the DTS Wizard in SQL Server Express edition as follows:

http://cfsilence.com/blog/client/index.cfm/2007/1/16/SQL-Server-2005-Express--DTS-Confirmed

Try this alternate method to import records from MySQL to SQL Server 2005.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question