Store UTF8 data in UTF16 column

krhodez

New Member
I'm storing XML in an XML column in SQL Server. SQL Server stores the data internally in UTF-16. Therefore the XML that is stored has to be in UTF-16.The XML I have is in utf-8, it has this declaration on top:\[code\]<?xml version="1.0" encoding="UTF-8" ?>\[/code\]When I try to insert xml with the UTF-8 declaration I get an exception saying something about the encoding. I can easily fix this in two ways:
  • by removing the declaration or
  • by changing the declaration to
: \[code\]<?xml version="1.0" encoding="UTF-16" ?>\[/code\]ProblemI don't know if it's 'safe' or correct to just remove or replace the declaration. Will I lose data, or will the XML become corrupt? Or do I have to convert the string in C# from utf-8 to utf-16?
 
Back
Top