3

By default, the SQL connection option ARITHABORT is OFF for OLEDB connections, which I assume Linq To SQL is using. However I need it to be ON. The reason is that my DB contains some indexed views, and any insert/update/delete operations against tables that are part of an indexed view fail if the connection does not have ARITHABORT ON. Even selects against the indexed view itself fail if the WITH(NOEXPAND) hint is used (which you have to use in SQL Standard Edition to get the performance benefit of the indexed view).

Is there somewhere in the data context I can specify I want this option ON? Or somewhere in code I can do it??

I have managed a clumsy workaround, but I don't like it .... I have to create a stored procedure for every select/insert/update/delete operation, and in this proc first run SET ARITHABORT ON, then exec another proc which contains the actual select/insert/update/delete. In other words the first proc is just a wrapper for the second. It doesn't work to just put SET ARITHABORT ON above the select/insert/update/delete code.

4
  • What version of SQL Server are you using? If later than SQL2000 it shouldn't care about this unless ANSI_WARNINGS is also off (unless you have the database in SQL 2000 compatibility level) sqlblog.com/blogs/kalen_delaney/archive/2008/06/19/… Commented Jul 18, 2010 at 8:44
  • Its SQL 2005. Yes, it is on automatically for manual queries run through Management Studio, but OLEDB has it turned off (so if you are writing an application the setting will be off for the application's SQL connections).
    – Laurence
    Commented Jul 19, 2010 at 16:16
  • Laurence, are you sure that OLE DB connections explicitly turn off this setting? The documentation for ALTER DATABASE does not say that it does (nor for NUMERIC_ROUNDABORT), yet does state that the other options are explicitly stated for ODBC and OLE DB clients. I tested via .NET (OLE DB) and SQLCMD.EXE (ODBC) and neither of them required any setting of ARITHABORT in order for me to SELECT and UPDATE an Indexed View. Were you getting an error prior to doing the helper class as noted in your answer? Commented Mar 20, 2015 at 19:35
  • The exception occurred running an insert/update/delete operation against tables that were part of an indexed view, not the view itself. I can only say I had this issue with Linq to SQL, and also later with Entity Framework.
    – Laurence
    Commented Mar 21, 2015 at 22:11

1 Answer 1

3

What I ended up doing was writing my own method in my own "helper" class to create the datacontext and using this every time I need a datacontext, e.g.

      Dim conn As New SqlConnection(Config.GetConnectionString("SiteSqlServer"))
      Dim command As New SqlCommand("set arithabort on;", conn)
      command.Connection.Open()
      command.ExecuteNonQuery()
      Dim dc = New SiteDataContext(conn)

The idea here is to use the datacontext constructor that takes a connection as a parameter. I create and open a SqlConnection, run "set arithabort..." on it, and pass it to the DC (credit goes to poster here).

2
  • I'm having issues with this leaving connections open. Did you run into this? What can I to avoid this.
    – drizzie
    Commented Sep 3, 2014 at 18:38
  • No sorry, I did not get that issue. Maybe look at whether you are disposing of your datacontext?
    – Laurence
    Commented Sep 4, 2014 at 21:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.