![](/img/trans.png)
[英]String or binary data would be truncated. The statement has been terminated?8
[英]Selective Xml Index causing Insert Error: string or binary data would be truncated. the statement has been terminated
我收到錯誤:
字符串或二進制數據將被截斷。 該語句已終止。
通過Linq-to-SQL從C#將XElement
數據插入SQL Server 2012 Xml
列中導致此錯誤。
運行Profiler和其他工具后,我發現XML中的一個屬性引起了錯誤:
我在C#代碼中使用了此代碼:
XmlDocument.SchemaVersion = System.Reflection.Assembly.GetAssembly(typeof(Data.Schema.Document)).GetName().Version.ToString();
這應該給輸出類似
<tst:Root xmlns:tst="http://tempuri.org/some.xsd" SchemaVersion="0.2.1234.12345" RevNumber="1">
...
...
</tst:Root>
但這導致引發錯誤,但這是:
如果我進行如下測試,則SchemaVersion="3"
或SchemaVersion"0.2.123.1"
可以正常工作:
XmlDocument.SchemaVersion = "0.2.123.1"
SQL Server的XML列上沒有SchemaCollection來強制錯誤。
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" />')
作品:
Insert into XmlTable(XmlId, XmlColumn)
Values('1', '<tst:Root xmlns:tst="http://tempuri.org/some.xsd" SchemaVersion="0.2.1234.1" RevisionNumber="1" />')
Selective Xml Index
指定的數據類型導致錯誤:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.