4

We are having some performance issues with our EF4 MVC solution. We've been able to track it down to ArithAbort getting set to off before all connections to the database, and now we are trying to force it to stay as 'ON'.

We've looked at: How do you control the "SET" statements emitted by Linq to SQL

But it seems like EF4 is resetting the connection before each query, so that won't work.

So far we've tried "set ArithAbort on" before a given query, with no luck. We've also tried going the long way and making a new connection where we set it, but still no luck.

So, anyone have a clue as to how we can get it to set it before making any linq queries against the database?

Changing database settings isn't an option.

Edit: Per Andiihs suggestion I tried out the wrapper solution and added in the following lines of code to the EFCachingCommand class

    protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
    {
        if (this.WrappedCommand.CommandType == System.Data.CommandType.Text)
        {
            this.WrappedCommand.CommandText = "set arithabort on; " + this.WrappedCommand.CommandText;
        }

This essentially ensures that any Linq-sql calls get prefixed with the right set statement.

I also had to add:

    DbFunctionCommandTree functionTree = commandTree as DbFunctionCommandTree;
    if (functionTree != null)
    {
        this.IsModification = true;
        return;
    }

To the GetAffectedEntitySets function in the EFCachingCommandDefinition, in order to get it to work properly with stored procedure calls.

Community
  • 1
  • 1
Grubsnik
  • 918
  • 9
  • 25
  • Thanks for posting this question. The linked article on MSDN is very long. Could you please post a full answer to your own question, with a step-by-step explanation of how to fix the problem? Thanks! – Shaul Behr May 08 '13 at 10:34
  • I must admit it's been a while since I worked with this problem. I'm fairly sure all I did was include the wrapper classes out of the box that Andiih linked first in his response and then modified them as described in my modified question. – Grubsnik May 13 '13 at 13:53

1 Answers1

4

EF provides the ability to insert a Wrapping Provider between Entity Connection and SQL.Data.Client - see http://code.msdn.microsoft.com/EFProviderWrappers and http://blogs.msdn.com/b/jkowalski/archive/2009/06/11/tracing-and-caching-in-entity-framework-available-on-msdn-code-gallery.aspx

Now I admit this is more of a clue than an answer - but perhaps you can insert the relevant set at this point ?

Andiih
  • 12,285
  • 10
  • 57
  • 88