C# 导致插入错误的选择性Xml索引:字符串或二进制数据将被截断。声明已被终止
我收到了错误信息:C# 导致插入错误的选择性Xml索引:字符串或二进制数据将被截断。声明已被终止,c#,sql-server,sql-server-2012,C#,Sql Server,Sql Server 2012,我收到了错误信息: string or binary data would be truncated. the statement has been terminated. 字符串或二进制数据将被截断。声明已终止 将XElement数据从C#via Linq插入SQL Server 2012Xml列导致错误 运行Profiler和其他工具后,我发现XML中的一个属性导致了错误: string or binary data would be truncated. the statement ha
string or binary data would be truncated. the statement has been terminated.
字符串或二进制数据将被截断。声明已终止
将XElement
数据从C#via Linq插入SQL Server 2012Xml
列导致错误
运行Profiler和其他工具后,我发现XML中的一个属性导致了错误:
string or binary data would be truncated. the statement has been terminated.
我在C代码中使用了这个:
这应该会产生如下输出
<tst:Root xmlns:tst="http://tempuri.org/some.xsd" SchemaVersion="0.2.1234.12345" RevNumber="1">
...
...
</tst:Root>
SQL Server中的XML列上没有强制执行错误的命令
SQL Server是否在没有用户定义的情况下以某种方式将SchemaVersion
属性强制为特定长度,或者为什么我使用的C#语句会导致错误
编辑:
添加了手动测试时失败并正常工作的示例Sql
失败:
Insert into XmlTable(XmlId, XmlColumn)
Values('1', '<tst:Root xmlns:tst="http://tempuri.org/some.xsd" SchemaVersion="0.2.1234.12345" RevisionNumber="1" />')
插入到XmlTable(XmlId,XmlColumn)
值('1','')
作品:
Insert into XmlTable(XmlId, XmlColumn)
Values('1', '<tst:Root xmlns:tst="http://tempuri.org/some.xsd" SchemaVersion="0.2.1234.1" RevisionNumber="1" />')
插入到XmlTable(XmlId,XmlColumn)
值('1','')
选择性Xml索引中指定的数据类型导致错误:
string or binary data would be truncated. the statement has been terminated.
我会发布索引,这样如果其他人有这个问题,也许会有所帮助
根据指定的长度检查长度,并对其进行更改,为我解决了问题
CREATE SELECTIVE XML INDEX [xsi_XmlTable] ON [dbo].[XmlTable]
(
[XmlColumn]
)
WITH XMLNAMESPACES
(
DEFAULT 'http://tempuri.org/some.xsd'
)
FOR
(
[1] = '/Root' as XQUERY 'node()',
[2] = '/Root/@SchemaVersion' as SQL [nvarchar](10) SINGLETON
)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90)
GO
选择性Xml索引中指定的数据类型导致错误:
string or binary data would be truncated. the statement has been terminated.
我会发布索引,这样如果其他人有这个问题,也许会有所帮助
根据指定的长度检查长度,并对其进行更改,为我解决了问题
CREATE SELECTIVE XML INDEX [xsi_XmlTable] ON [dbo].[XmlTable]
(
[XmlColumn]
)
WITH XMLNAMESPACES
(
DEFAULT 'http://tempuri.org/some.xsd'
)
FOR
(
[1] = '/Root' as XQUERY 'node()',
[2] = '/Root/@SchemaVersion' as SQL [nvarchar](10) SINGLETON
)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90)
GO