Persisted computed column and ARITHABORT

Posts   
 
    
paulshealy
User
Posts: 22
Joined: 13-Jun-2005
# Posted on: 13-Aug-2007 20:08:23   

I'm using SQL Server 2005 with LLBLGen version 2.0, the latest build. I've recently added a persisted computed column with the definition:

[Date]  AS (CONVERT([datetime],CONVERT([varchar],[start],(101)),(101))) PERSISTED NOT NULL

and now I get an error message when deleting entities from the table:

DELETE 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.

I've added a call to DbUtils.SetArithAbortFlag(true) and it does work. From SQL Server Profiler:


BEGIN TRANSACTION tx
go
exec sp_executesql N'SET ARITHABORT ON;DELETE FROM [heathandcocom1].[ScheduleEntry] WHERE ( ( ( ( ( [heathandcocom1].[ScheduleEntry].[HotelID] = @HotelID1 AND [heathandcocom1].[ScheduleEntry].[IsTemplate] = @IsTemplate2) AND [heathandcocom1].[ScheduleEntry].[Start] >= @Start3) AND [heathandcocom1].[ScheduleEntry].[Start] < @Start4) AND [heathandcocom1].[ScheduleEntry].[AssignmentID] IN (@AssignmentID5)));SET ARITHABORT OFF;',N'@HotelID1 int,@IsTemplate2 bit,@Start3 datetime,@Start4 datetime,@AssignmentID5 int',@HotelID1=22,@IsTemplate2=0,@Start3='2007-06-01 00:00:00:000',@Start4='2007-06-08 00:00:00:000',@AssignmentID5=26
go

But this query still fails with the same message. However, if I move the 'SET ARITHABORT ON' statement to before the 'exec' call (in Query Analyzer), the query succeeds.

I can work around it if needed by making the column non-computed and updating the field before saving.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 14-Aug-2007 04:53:52   

How are you adding the DbUtils.SetArithAbortFlag(true) at code? Could you post the code snippet?

What if you start a transaction, then call DBFuncionCall in that trans and then call DELETE, finally commit trans?

David Elizondo | LLBLGen Support Team
paulshealy
User
Posts: 22
Joined: 13-Jun-2005
# Posted on: 14-Aug-2007 20:58:16   

daelmo wrote:

How are you adding the DbUtils.SetArithAbortFlag(true) at code? Could you post the code snippet?

Here's the original code:

PredicateExpression filter = (ScheduleEntryFields.HotelID == HotelId())
                                         & (ScheduleEntryFields.IsTemplate == false)
                                         & (ScheduleEntryFields.Start >= dates.StartDate)
                                         & (ScheduleEntryFields.Start < dates.EndDate)
                                         & ScheduleEntryFields.AssignmentID.EqualTo(assignmentIDs);
DbUtils.SetArithAbortFlag(true);
new ScheduleEntryCollection().DeleteMulti(filter);

What if you start a transaction, then call DBFuncionCall in that trans and then call DELETE, finally commit trans?

Not sure what you mean here... the problem isn't using the computed field in a query. The problem is that SQL Server won't let you insert, update, or delete in a table with a persisted computed column when arithabort is set to off.

I was able to hack around it by using the DAAB and adding a "set arithabort on" call where the DbUtils.SetArithAbortFlag(true) line is above, and that worked.

paulshealy
User
Posts: 22
Joined: 13-Jun-2005
# Posted on: 14-Aug-2007 21:31:53   

daelmo wrote:

How are you adding the DbUtils.SetArithAbortFlag(true) at code? Could you post the code snippet?

What if you start a transaction, then call DBFuncionCall in that trans and then call DELETE, finally commit trans?

Found the following KB article http://support.microsoft.com/kb/305333 that addresses the issue (even though it's for ADO):

To successfully insert a row into a table that is referenced in an indexed view, the SQL ARITHABORT configuration setting must be set to ON. Furthermore, the statement that applies this configuration setting must be executed in its own batch.