minchul.kang
minchul.kang

Reputation: 13

SQL Server : varchar reading unicode issue

We are using a SQL Server database and C++, and we have several inquiries about the issues we are currently facing.

Here's some information about our situation:

  1. Chinese_Taiwan_Stroke_CI_AS is being used as collation in the database
  2. In a stored procedure, VARCHAR(200) is used as a parameter
  3. The server calls A procedure, and it passes Unicode(UTF-8) to the VARCHAR parameter

Due to this, data corruption occurs when a value is stored in the database. So far, we have understood up to this part.

These are the results we obtained after the tests we did

  1. String that is broken after it being delivered to the server is 韓國人學台語.
  2. If we check the OUTPUT with SELECT '韓國人學台語' COLLATE Chinese_Taiwan_Stroke_CI_AS, the string comes out normally without being broken.
  3. Also, when SQL Server directly calls A procedure and sends 韓國人學台語 to the parameter, the data is normally displayed.

This is the inquiry we want to ask: when you store Unicode value in VARCHAR, it appears that the results are shown differently when you store the data through the server and when you save it through running T-SQL query directly.

We need your explanation about this part.

--------------------------------------------------Edit!

I am using a translator. i look forward to your understanding.,_,)

I am careful to raise problem the stored procedure and the schema of the table uploaded.

I have read many replies with thanks,

if i using unicode, I understood if not using approciate Collation-Rule, we need using NVARCHAR.

As ZLK said, we believe there is a problem with the way the server delivers it. We'll look further and we'll leave a message as soon as we know the cause.

Thank you for your reply.

Upvotes: 1

Views: 482

Answers (1)

Joel Coehoorn
Joel Coehoorn

Reputation: 416149

If you want to use UTF-8, use the NVARCHAR type and make sure to use an N prefix with any string literals, like this: N'韓國人學台語'

Native UTF-8 support in the VARCHAR type is coming in the Sql Server 2019 release. Until then, you'll just have to use the larger type.

Upvotes: 1

Related Questions