Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 997
  • Last Modified:

View Arabic characters under SQL Express Edition

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
cooldude87801
Asked:
cooldude87801
  • 17
  • 14
1 Solution
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
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
 
cooldude87801Author Commented:
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
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
cooldude87801Author Commented:
the columns have nvarchar data type but still I cannot view the data.
0
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
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
 
cooldude87801Author Commented:
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
 
cooldude87801Author Commented:
There are several collations for Arabic under SSMS ...which one should I choose to view UTF8?
0
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
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
 
cooldude87801Author Commented:
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
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
>> 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
 
cooldude87801Author Commented:
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
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
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
 
cooldude87801Author Commented:
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
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
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
 
cooldude87801Author Commented:
I tried it out ...and I can view the Arabic characters very clear....

I am really puzzled???
0
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
>> 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
 
cooldude87801Author Commented:
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
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
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
 
cooldude87801Author Commented:
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
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
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
 
cooldude87801Author Commented:
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
 
cooldude87801Author Commented:
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
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
Kindly use this collation Arabic_CI_AI_WS and give it a try..
0
 
cooldude87801Author Commented:
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
 
cooldude87801Author Commented:
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
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
>> 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
 
cooldude87801Author Commented:
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
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
>> 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
 
cooldude87801Author Commented:
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
 
cooldude87801Author Commented:
Dear rrjegan17
I hope you are not raising the white flag!
0
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
>> 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 17
  • 14
Tackle projects and never again get stuck behind a technical roadblock.
Join Now