试图XML内容存储到SQL Server 2005的失败(编码问题) [英] Trying to store XML content into SQL Server 2005 fails (encoding problem)

查看:307
本文介绍了试图XML内容存储到SQL Server 2005的失败(编码问题)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,

我有返回ISO-8859-1编码数据的Web服务 - 因为它不是我的,我不能改变的: - (

I have a webservice that returns data in ISO-8859-1 encoding - since it's not mine, I can't change that :-(

有关审计的目的,我想从这些调用生成的XML存储到SQL Server 2005的表,其中我有型XML NULL的领域。

For auditing purposes, I'd like to store the resulting XML from these calls into a SQL Server 2005 table, in which I have a field of type "XML NULL".

这是我的C#code,我尝试使用参数化查询来存储这些XML内容到XML领域,像

From my C# code, I try to store this XML content into the XML field using a parametrized query, something like

SqlCommand _cmd = new SqlCommand("INSERT INTO dbo.AuditTable(XmlField) VALUES(@XmlContents)", _connection);

_cmd.Parameters.Add("@XmlContents", SqlDbType.Xml);
_cmd.Parameters["@XmlContents"].Value = (my XML response);

_cmd.ExecuteNonQuery();

麻烦的是 - 当我运行此code,我回来了一个错误:

Trouble is - when I run this code, I get back an error:

消息9402,级别16,状态行1结果
  XML解析:1号线,字符XY,无法切换编码

Msg 9402, Level 16, State 1, Line 1
XML parsing: line 1, character xy, unable to switch the encoding

?我想弄清楚在何处和如何我可能开关的编码 - 至今没有运气。这是什么究竟意味着什么?我不能存储XML与SQL Server 2005的ISO-8859-1编码?或者是有一招一)告诉SQL Server 2005中只接受这种编码,或b)在SQL Server存储之前,自动地转换web服务响应UTF编码?

?? I was trying to figure out where and how I could possibly "switch" the encoding - no luck so far. What does this really mean? I cannot store XML with ISO-8859-1 encoding in SQL Server 2005?? Or is there a trick to a) tell SQL Server 2005 to just accept this encoding, or b) to automagically convert the webservice response to UTF encoding before storing in SQL Server?

感谢您的任何提示,三分球,技巧!
马克

Thanks for any hints, pointers, tips! Marc

推荐答案

您需要转换为UTF-16

我不是XML在SQL Server中,即使我用它的专家,但我们有同样的问题,去年,它是相对于正在发送的XML在SQL声明的字符串数据类型不匹配。

I'm not an expert on XML in SQL Server even though I use it, but we had the same problem last year and it was mis-match of the string datatype declared in SQL compared to the xml being sent.

这篇关于试图XML内容存储到SQL Server 2005的失败(编码问题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆