I have a problem with characters encoding in my ms sql server (version Enterprise 2014). I create bulk files via c# program, bulk are encoded in UTF-8 with polish characters, but when I insert bulk into my database instead of strings with polish characters I have strings with default ASCII characters.
Here is my create table declaration:
create table Klient
(
imie varchar(20),
nazwisko varchar(40),
id int identity(1,1),
primary key (id),
)
Here is a part of my bulk file:
...
Sylwiusz|Okyne|1
Adolf|Osientowicz|2
Jagoda|Chołyś|3
Wanda|Peryhasza|4
Milena|Czybieniak|5
Katarzyna|Czarnopyś|6
Witomir|Chałubowicz|7
Rut|Garuz|8
Rut|Sciolny|9
Klementyna|Leszer|10
Lucjusz|Boralciewicz|11
...
Here is a script which push bulk to the database:
BULK INSERT Klient FROM 'src' WITH (KEEPIDENTITY, FIELDTERMINATOR='|', ROWTERMINATOR = '\n');
Here is my database properties:
Here is properties of column which has string with polish characters:
And here is what it looks into my database:
I also try using nvarchar instead of varchar but it didn't help for me. Maybe I should use another collation? But I don't have idea which one because there is about 30-40 polish collations.. So if someone could help me I will be very grateful!
Regarding to @Giorgios answer adding codepage="65001" didn't help for me because sql server returns info that he isn't support it. I also find info that sql server never support codepage 65001, but it's a info from 2009, but I don't know if it's actual with sql server 2014..
Regarding to my edit, and what @Roger F. Wolf said. Ms sql doesn't support UTF-8. And to deal with this I change method of generating data to the database. In my c# program to create bulk file instead of using:
using (var sr = new StreamWriter(String.Format("{0}.bulk", this.clientPath))
I use this:
using (var sr = new StreamWriter(File.Open(String.Format("{0}.bulk", this.clientPath), FileMode.CreateNew), Encoding.Unicode)
And for me it works fine! Here is what I get:
My bulk file:
and select from my database:
and also communique from sql:
Solution to this sql communique, is what @Roger said (adding DATAFILETYPE to sql script with bulk insert)
BULK INSERT Klient FROM 'src' WITH (KEEPIDENTITY, FIELDTERMINATOR='|', ROWTERMINATOR = '\n', DATAFILETYPE='widechar');
Thanks for help!