-1

I have this row:

enter image description here

You see, inside the column "description" there is already a russian character set saved.

Now if I literally COPY what is already inside that table and do:

UPDATE [SystemLocalization]
SET Description = '<p>Дополнительная форма для другого внешнего вида продукта</p>

<ul>
    <li>Величина порции: 350 г</li>
    <li>Длина порции: 150 мм</li>
    <li>Ширина порции: 120 мм</li>
    <li>Высота порций: 25 мм</li>
    <li>Диаметр отверстий концевой решетки: 3 мм</li>
    <li>Тара: Лоток</li>
    <li>Наружные размеры лотка ДxШxВ: 195 x 144 x 51 см</li>
</ul>
' 
WHERE Id = 3179;

The result is this:

enter image description here

So clearly, there must have been used a trick while storing the russian string inside this column, as it already accepts russian values.

What might this trick be?

Also; when I do this:

SELECT COLUMN_NAME, COLLATION_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'SystemLocalization' 
  AND COLUMN_NAME = 'Description';

I am getting: Latin1_General_CI_AS

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
innom
  • 770
  • 4
  • 19
  • Show us your `CREATRE TABLE` statement for that table. – Dai Jul 12 '23 at 13:12
  • `SET Description = '

    Дополн` <-- Your string-literal here is `varchar`, not `nvarchar` (and you need to use `nvarchar` to preserve Unicode text): add a `N` prefix to the string to make it an nvarchar literal.

    – Dai Jul 12 '23 at 13:13
  • `COLLATION` (for the most-part) only affects text comparison, not storage (the exception is when you're using `_SC` collation - or getting UTF-8 to work with `varchar` columns), but if you're able to you probably should do `ALTER TABLE SystemLocalization ALTER Description nvarchar(?) COLLATE Cyrillic_General_100_CI_AI_SC` – Dai Jul 12 '23 at 13:18

1 Answers1

1

You need to add a N prefix to the string-literal to SQL Server knows the string-literal contains Unicode text:

Change SET Description = '<p>Д... to SET Description = N'<p>Д....

Like so:

UPDATE [SystemLocalization]
SET Description = N'<p>Дополнительная форма для другого внешнего вида продукта</p>

<ul>
    <li>Величина порции: 350 г</li>
    <li>Длина порции: 150 мм</li>
    <li>Ширина порции: 120 мм</li>
    <li>Высота порций: 25 мм</li>
    <li>Диаметр отверстий концевой решетки: 3 мм</li>
    <li>Тара: Лоток</li>
    <li>Наружные размеры лотка ДxШxВ: 195 x 144 x 51 см</li>
</ul>
' 
WHERE Id = 3179;

...otherwise the string will be interpreted as varchar (not nvarchar) which (by default) uses the system codepage which will lose Unicode data.

Dai
  • 141,631
  • 28
  • 261
  • 374
  • thank you. that did fix it. I have a special question: i am also doing this update from my asp.net application. How can I tell my string I am putting in there to have the "N" prefix? Thank you! – innom Jul 12 '23 at 13:31
  • ...aren't you using `SqlParameter` to pass values into your `SqlCommand` objects? If so, all you need to do is ensure you specify `SqlDbType.NVarChar`. – Dai Jul 12 '23 at 13:32
  • unfortunetely no. I am using sqlite framework to update db; all i can do is "context.SubmitChanges()" on an item. – innom Jul 12 '23 at 13:49
  • Sqlite isn't SQL Server... but `context.SubmitChanges()` is for Linq-to-SQL - which _only_ works with SQL Server - so you aren't making much sense right now. (Anway, you **should not** be using Linq-to-SQL anymore: it isn't supported by .NET Core, you should be using EF instead) – Dai Jul 12 '23 at 13:51
  • im sorry, you were right. it is linq to sql (my bad). i dont think I can update the whole framework... the funny thing is, it works on already existing things, only the function that I write seem to fail with this error... thanks so far. – innom Jul 12 '23 at 13:56
  • 1
    Your Linq-to-SQL configuration code probably just needs to be adjusted to ensure it uses `nvarchar`, - but I just found this and I think it's a bug/limitation in Linq-to-SQL: https://stackoverflow.com/questions/1699382/linq-to-sql-nvarchar-problem - so you _really_ should stop using 15-year-old-dead-end frameworks and use EF. – Dai Jul 12 '23 at 13:58
  • youre ofc right; but tell that to the client on a budget ;-) – innom Jul 12 '23 at 14:09
  • When I'm consulting I never ask for the client's approval for _essential upgrades_: they hired me for my expertise, and my expertise says _rip it out_ :) – Dai Jul 12 '23 at 14:10