5

I am using the seed method to populate the database. Some of the objects have properties in cyrillic. Example:

context.Wines.AddOrUpdate(new Wine()
       {
           Id = 1,
           Name = "Шардоне",
           etc........................................

The objects are properly created in the database, however when I check the database in MS SQL management studio instead of the wine's name being "Шардоне", it is displayed as "Øàðäîíå".

Strangely, when I create the wine in my Startup class like this:

var db = new WineSystemDbContext();
var ShardoneWine = new Wine { Name = "Шардоне};
db.Wines.Add(ShardoneWine);

everything is displayed properly in cyrillic in the database.

Do you have an idea what may cause this?

Cœur
  • 37,241
  • 25
  • 195
  • 267
mega_n00b
  • 53
  • 6

5 Answers5

5

You can specify the charset of your connectin in connection string. Just add this part to your connection:

charset=UTF8;

If no results you can try to change char-set of Configuration.cs file. There are two ways to do that.

  1. Close Configuration.cs in Visual Studio editor, then right-click on that file in Solution Explorer and select "Open With..." -> "CSharp Editor with Encoding" and from a list choose "Unicode (UTF-8 with signature) - Codepage 65001" option (try other codepage if this one will show you some 'Chinese' symbols). Now fix your cyrilic chapters and save Configuration.cs file.
  2. Select "File" -> "Advanced Save Options" and save file with the method that seed data with the UTF-8 encoding.

You can also have problems if you are using ntext column type.

Community
  • 1
  • 1
Vadim Martynov
  • 8,602
  • 5
  • 31
  • 43
0

In order to store e.g. Cyrillic characters, they must be nvarchar(x) At least from my experience.

I've seen the same phenomenom: with varchar(100) the data goes in fine but comes out ???- but with nvarchar(100) everything seems to be fine.

McBooley
  • 433
  • 1
  • 5
  • 16
0

In your query need to add de N (to tells SQL Server that it is unicode), example:

SELECT * FROM Wines WHERE someColumn = N'sometext'
Rodolfo
  • 247
  • 2
  • 14
0

I found a solution!

Here is what I did (found it in another topic)

Open your's Configuration.cs file in Solution Explorer, copy Seed method and paste code in Windows Notepad for example (temporarily).

"Next close Configuration.cs in Visual Studio if you have it opened, then right-click on that file in Solution Explorer and select "Open With..." -> "CSharp Editor with Encoding" and from a list choose "Unicode (UTF-8 with signature) - Codepage 65001" option (try different option when this one will show you some 'chinese' characters).

Replace Seed method with that from Notepad. Save, delete existing data from database and Update-Databse. Your country characters shoud now display correctly.

Cheers."

Thanks for the help everyone

mega_n00b
  • 53
  • 6
0

I was helped by the following: Select "File" -> "Advanced Save Options" and save file with the method that seed data with the UNICODE (UTF-8 with signature) encoding and Line endings - Current settings.