Solved

View Arabic characters under SQL Express Edition

Posted on 2009-07-09
32
858 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
  • 17
  • 14
32 Comments
 
LVL 57

Expert Comment

by:Raja Jegan R
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

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

Expert Comment

by:Raja Jegan R
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
>> 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I tried it out ...and I can view the Arabic characters very clear....

I am really puzzled???
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 57

Expert Comment

by:Raja Jegan R
Comment Utility
>> 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Kindly use this collation Arabic_CI_AI_WS and give it a try..
0
 

Author Comment

by:cooldude87801
Comment Utility
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
Comment Utility
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
Comment Utility
>> 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
Comment Utility
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
Comment Utility
>> 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
Comment Utility
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
Comment Utility
Dear rrjegan17
I hope you are not raising the white flag!
0
 
LVL 57

Accepted Solution

by:
Raja Jegan R earned 500 total points
Comment Utility
>> 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now