1

I have exported my data to text File. It was open in file as utf-8 encoding. Then I've changed some text and tried to import it back to the database but now there are no Greek letters.

Coding is gone :(

How should I encode text file with inserts so that I don't loose coding after insert to database ?

thanks for any help

APC
  • 144,005
  • 19
  • 170
  • 281
gruber
  • 28,739
  • 35
  • 124
  • 216
  • 1
    Can you show us the SQL code and tables please? – gbn Sep 10 '11 at 17:06
  • Might not be an issue but keep in mind that SQL Server will always store XML using utf-8 encoding. So if your application is not saving the file as utf-8 after edits you make it can result in characters being interpreted incorrectly as SQL Server attempts to convert it back into utf-8. – Yuck Sep 10 '11 at 17:12
  • file is converted to utf-8, still doesnt work – gruber Sep 10 '11 at 17:20
  • @Yuck: The UTF is decided by the string and the encoding in the data. Internally it is always UTF-16 http://stackoverflow.com/questions/6857760/saving-xml-contents-with-iso-8859-1-encoding-using-entity-framework-into-sql-serv/6857882#6857882 and http://stackoverflow.com/questions/6888984/what-is-the-range-or-ms-sql-xml-argument/6889266#6889266 – gbn Sep 10 '11 at 17:23
  • How can I convert my utf-8 file to utf-16 so that I can easily insert it to database ? I ve got more thank 2 k insert commands and as I cand understand I just need to convert that file to utf-16 – gruber Sep 10 '11 at 17:32
  • 1
    @gruber: you don't have to convert it. What you have done is INSERTed it as a varchar literal most likely before it became xml. However, you haven't given us any sample code to verify this. And read my answer here: http://stackoverflow.com/questions/6857760/saving-xml-contents-with-iso-8859-1-encoding-using-entity-framework-into-sql-serv/6857882#6857882 – gbn Sep 10 '11 at 17:37

1 Answers1

0

tried to import it back to the database but now there are no Greek letters

Based on the insert from your other post: problem with greek encoding while inserting sql server where you discuss a similar problem, I see two likely culprits:

  1. the destination column [MC_LIST].[data] is a non Unicode datatype (such as nvarchar, nchar). the varchar datatype will store the Greek characters as ?

  2. and/or you are inserting string literals without the N prefix Example, this will fail:

INSERT INTO myDB.[MC_LIST] ([data]) VALUES ('1gr/products/how-does-nioxin-works-page.aspxaltΠΡΟΣΕΓΓΙΣΗ ΦΡΟΝΤΙΔΑΣ ΤΗΣ ΕΠΙΔΕΡΜΙΔΑΣ/m/photo/box-4.jpgΚάθε προϊόν lala περιέχει έναν εξειδικευμένο συνδυασμό συστατικών επιστημονικής προέλευσης. ΟΙ ΤΕΧΝΟΛΟΓΙΕΣ ΜΑΣΠΡΟΣΕΓΓΙΣΗ ΦΡΟΝΤΙΔΑΣ ΤΗΣ ΕΠΙΔΕΡΜΙΔΑΣ') ;

Whereas this will work:

INSERT INTO myDB.[MC_LIST] 
    ([data]) 
 VALUES 
    (N'<data><id>1</id><language>gr</language><szonelinkdest>/products/how-does-nioxin-works-page.aspx</szonelinkdest><szoneimgalt>alt</szoneimgalt><title>ΠΡΟΣΕΓΓΙΣΗ ΦΡΟΝΤΙΔΑΣ ΤΗΣ ΕΠΙΔΕΡΜΙΔΑΣ</title><szoneimg>/m/photo/box-4.jpg</szoneimg><szonedesc>Κάθε προϊόν lala περιέχει έναν εξειδικευμένο συνδυασμό συστατικών επιστημονικής προέλευσης. </szonedesc><szonelinkname>ΟΙ ΤΕΧΝΟΛΟΓΙΕΣ ΜΑΣ</szonelinkname><szonetitle>ΠΡΟΣΕΓΓΙΣΗ ΦΡΟΝΤΙΔΑΣ ΤΗΣ ΕΠΙΔΕΡΜΙΔΑΣ</szonetitle></data>') ;
Jeff Mergler
  • 1,384
  • 20
  • 27