2

I am trying to save XML content with encoding="ISO-8859-1" standalone="yes" into a SQL Server 2008 XML column. I am doing this using Entity Framework.

However doing this throws the following error

XML parsing: line 1, character 60, unable to switch the encoding

However when I try to save XML content with encoding UTF-16, it is saved without any error.

Does anyone have any inputs regarding this?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
surajnaik
  • 725
  • 2
  • 10
  • 26

1 Answers1

2

The encoding width must match the datatype width

So don't send:

  • UTF-8 and nvarchar/xml
  • UTF-16 and varchar

Also see Trying to store XML content into SQL Server 2005 fails (encoding problem) whcih links to http://social.msdn.microsoft.com/forums/en-US/sqlxml/thread/d40ef582-4ffe-4f4b-b6b8-03c6c0ba1a32/

Community
  • 1
  • 1
gbn
  • 422,506
  • 82
  • 585
  • 676
  • The datatype of the column in SQL Server 2008 is xml and that of property of corresponding class generated by Entity Framework is string. Also I am sending data with encoding ISO-8859-1. – surajnaik Jul 28 '11 at 11:08
  • @surajnaik: xml is effectively nvarchar in this case. You **have** to change encoding. – gbn Jul 28 '11 at 11:09