I have a stored procedure that updates my database.
It runs great in query analyzer, but when I try to run it from my C# web app, the table is not updated.
I am receiving the following error, so I set ARITHABORT to "ON", but I still receive the error.
UPDATE failed because the following SET options have incorrect settings: 'ARITHABORT'. Verify that SET options are correct for use with indexed views and/or indexes on computed columns and/or query notifications and/or xml data type methods.
C# Code:
p = new SqlParameter("@userAnswers", SqlDbType.VarChar, 1000);
p.Value = "";
p.Value = exam.ExamQuestions.Rows[0].ItemArray[0] + ":" + exam.UserAnswerChoices[0];
for (int x = 1; x < exam.NumQuestions; x++)
{
p.Value+= ", " + exam.ExamQuestions.Rows[x].ItemArray[0] + ":" + exam.UserAnswerChoices[x];
}
conn.query("insertAnswers", p);
return p.Value.ToString();
Stored procedure code:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ARITHABORT ON
GO
ALTER PROCEDURE [dbo].[insertAnswers]
@userAnswers VarChar(1000)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @input XML
Set @input = '<Questions><Question id="' + Replace(Replace(@userAnswers, ':', '">'), ', ', '</Question><Question id="') + '</Question>' + '</Questions>'
;WITH ParsedXML AS
(
SELECT
ID = C.value('(@id)[1]', 'int'),
ColumnName = C.value('(.)[1]', 'varchar(10)')
FROM @input.nodes('/Questions/Question') AS T(C)
)
UPDATE CourseQuestions
SET a = CASE WHEN p.ColumnName = 'a' THEN t.a + 1 ELSE t.a END,
b = CASE WHEN p.ColumnName = 'b' THEN t.b + 1 ELSE t.b END,
c = CASE WHEN p.ColumnName = 'c' THEN t.c + 1 ELSE t.c END,
d = CASE WHEN p.ColumnName = 'd' THEN t.d + 1 ELSE t.d END,
e = CASE WHEN p.ColumnName = 'e' THEN t.e + 1 ELSE t.e END,
f = CASE WHEN p.ColumnName = 'f' THEN t.f + 1 ELSE t.f END
FROM CourseQuestions t
INNER JOIN ParsedXml p ON t.QuestionID = p.ID
END
@userAnswers
is basically a comma-separated string (since I can't send an array to SQL Server). It looks like: '1:d, 2:a, 3:b'