我的代码插入数据,这些数据作为XML从C#代码传递到本地正常工作到SQL Server 2008,但在SQL Server 2005的远程实例上,它抛出以下异常。请帮忙。
CREATE PROCEDURE SqAnswersInsert @AnswerID INT OUTPUT,
@ClientID INT = NULL,
@VGBID INT = NULL,
@CreatedOn DATETIME = NULL,
@XmlOptions XML = NULL AS BEGINSET ARITHABORT ON INSERT SqAnswers (ClientID, VGBID, [CreatedOn]) VALUES (@ClientID, @VGBID, @CreatedOn) SET @AnswerID=Scope_identity() INSERT INTO SqAnswerOptions (AnswerID, QuestionOptionID) SELECT @AnswerID,A.B.value('QuestionOptionID[1]', 'INT') AS QuestionOptionID --A.B.value('QuestionOptions/QuestionOptionID', 'INT') as QuestionOptionID FROM @XmlOptions.nodes('/QuestionOptions/Option') A(B) SET ARITHABORT OFF END
INSERT失败,因为以下SET选项的设置不正确:'ARITHABORT'。验证SET选项是否正确,以便与计算列和/或筛选索引和/或查询通知和/或XML数据类型方法和/或空间索引操作的索引视图和/或索引一起使用。
答案 0 :(得分:2)
如果数据库中有索引视图,则在执行任何其他SQL命令之前,每次连接到Microsoft SQL Server时都必须执行SQL命令
SET ARITHABORT ON
。
您可以通过删除数据库视图中的索引来消除此错误
SET ARITHABORT在查询执行期间发生溢出或被零除错误时终止查询。
来自Technet
1. If SET ARITHABORT is ON and SET ANSI WARNINGS is ON, these error
conditions cause the query to terminate.
2. If SET ARITHABORT is ON and SET ANSI WARNINGS is OFF, these error
conditions cause the batch to terminate. If the errors occur in a
transaction, the transaction is rolled back. If SET ARITHABORT is
OFF and one of these errors occurs, a warning message is displayed,
and NULL is assigned to the result of the arithmetic operation.
3. If SET ARITHABORT is OFF and SET ANSI WARNINGS is OFF and one of
these errors occurs, a warning message is displayed, and NULL is
assigned to the result of the arithmetic operation.
答案 1 :(得分:0)
SET
ANSI_NULLS,
QUOTED_IDENTIFIER,
CONCAT_NULL_YIELDS_NULL,
ANSI_WARNINGS,
ANSI_PADDING
ON;
INSERT INTO TABLE(@CLOUMNS) VALUES(@VALUE)