【问题标题】:Getting Error as INSERT failed because the following SET options have incorrect settings由于以下 SET 选项的设置不正确,导致 INSERT 失败
【发布时间】:2014-03-07 10:12:51
【问题描述】:

我的代码将作为 XML 从 C# 代码传递的数据插入 SQL Server 2008,但在 SQL Server 2005 的远程实例上它会引发以下异常。请帮忙。

创建过程 SqAnswersInsert @AnswerID INT 输出,
@ClientID INT=NULL,
@VGBID INT=NULL,
@CreatedOn DATETIME=NULL,
@XmlOptions XML=NULL AS BEGIN

  SET 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

插入失败,因为以下 SET 选项的设置不正确:“ARITHABORT”。验证 SET 选项是否适用于索引视图和/或计算列上的索引和/或过滤索引和/或查询通知和/或 XML 数据类型方法和/或空间索引操作。

【问题讨论】:

  • 你能发布你的查询吗??
  • @NagarajS 请立即查看查询

标签: c# sql sql-server


【解决方案1】:
SET 
ANSI_NULLS, 
QUOTED_IDENTIFIER, 
CONCAT_NULL_YIELDS_NULL, 
ANSI_WARNINGS, 
ANSI_PADDING 
ON;

INSERT INTO TABLE(@CLOUMNS) VALUES(@VALUE)

【讨论】:

    【解决方案2】:

    当您的数据库中有索引视图时,您必须在每次连接到 Microsoft SQL Server 之前执行 SQL 命令
    SET ARITHABORT ON,然后再执行任何其他 SQL 命令。

    您可以通过从数据库视图中删除索引来消除此错误

    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.
    

    【讨论】:

    • 感谢 Vignesh,我的问题已解决,但是当我不使用算术运算或任何索引视图时,为什么会出现此错误
    • @AjaySuwalka 你可能有登录会话
    猜你喜欢
    • 2017-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-20
    • 1970-01-01
    • 1970-01-01
    • 2012-01-13
    相关资源
    最近更新 更多