2014-02-10 66 views
1

我的代碼插入的數據是作爲XML從C#代碼中傳遞的,後面的代碼在本地正常工作到SQL Server 2008中,但在SQL Server 2005的遠程實例上拋出以下例外。請幫忙。由於INSERT失敗而陷入錯誤,因爲以下SET選項的設置不正確

CREATE PROCEDURE SqAnswersInsert @AnswerID INT OUTPUT,
@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 

INSERT失敗,因爲以下SET選項有不正確的設置:'ARITHABORT'。驗證SET選項是否適用於計算列和/或過濾索引和/或查詢通知和/或XML數據類型方法和/或空間索引操作的索引視圖和/或索引。

+0

您可以發佈您的查詢? –

+0

@NagarajS請檢查現在的查詢 –

回答

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. 
+0

謝謝Vignesh,我的問題已解決,但是當我沒有使用算術運算或任何索引視圖時,爲什麼我會收到此錯誤 –

+0

@AjaySuwalka您可能有登錄會話 –

+1

不,我沒有 –

0
SET 
ANSI_NULLS, 
QUOTED_IDENTIFIER, 
CONCAT_NULL_YIELDS_NULL, 
ANSI_WARNINGS, 
ANSI_PADDING 
ON; 

INSERT INTO TABLE(@CLOUMNS) VALUES(@VALUE) 
相關問題