0

i want to get data from sql server data base encoded in utf8 encoding

i have looked into it i found this answer : Is it possible to have SQL Server convert collation to UTF-8 / UTF-16 , i used collation utf8_unicode_ci in the query like this :

 select code collation utf8_unicode_ci  from testTable where code = 33; 

i got an error , i also found this link : Convert output of MySQL query to utf8, used this query :

select  CONVERT(CAST(code as BINARY) USING utf8) as code from testTable where code = 33; 

but i get "" at beginning of the output file . im lost now

user743414
  • 936
  • 10
  • 23
chawky
  • 81
  • 7
  • 1
    *"I got error"* doesn't tell us much. I assume, as you tried to use a UTF8 collation, that your using an RC version of SQL Server 2019? – Thom A Aug 29 '19 at 12:24
  • 1
    Which error do you get? – user743414 Aug 29 '19 at 12:24
  • Can you share the sample data you have stored in SQL Server database? And also share what exact output do you get with different query approaches you used. – Chetan Aug 29 '19 at 12:27
  • the error that i got was this : collation 'utf8_unicode_ci' is not valid – chawky Aug 29 '19 at 12:31
  • Once you take a bytes array an using UTF8 encoding you can't fix the issue by converting to UTF16. You may be able to take the UTF8 and convert to a byte[] and then take the byte[] and encode in UTF16. For example UTF8 encoding will change the 0x80 bytes and you will not be able to undo the change. – jdweng Aug 29 '19 at 12:32
  • the data i have is simple a table called test table it has 2 columns : code and date – chawky Aug 29 '19 at 12:32
  • If that collation is invalid then you aren't using SQL Server 2019. Earlier versions do not support UTF-8. – Thom A Aug 29 '19 at 12:34
  • well what should i do , im working locally now but when i deliver my solution to different clients they will have different versions of sql server , i need something to convert the data in the client side so it will be generic – chawky Aug 29 '19 at 12:36
  • that is why i wanted to edit the query so it gets the data encoded in utf8 encoding independent from what sql serve version they have – chawky Aug 29 '19 at 12:38
  • if there is anothere way in code im all ears – chawky Aug 29 '19 at 12:38
  • @ jdweng i dont want utf16 just need to convert data to that i got from a query to utf8 – chawky Aug 29 '19 at 12:40
  • Please [edit] to show how C# and an output file are involved. – Tom Blodget Aug 29 '19 at 14:33

0 Answers0