0

I'm using EF 4, and I'm stumped on another quirk... Basically, I have a fairly simple stored procedure that's responsible for retrieving data from SQL and returning a complex type. I have the stored procedure added to my model via a function import. It's more or less in the following structure.

using (ModelContainer context = GetNewModelContainer())
{
   return context.GetSummary(id, startDate, endDate, type).ToList();
} 

I should mention that the code above executes over a remote SQL connection. It takes nearly 10 minutes to execute. However, using SQL Server Management Studio over the remote connection, the stored procedure executes almost instantaneously.

There are only 100 records or so that are returned, and each record has approximately 30 fields.

When I run the code above locally (no remote connection) against a backup of the customer's database, it executes without any delay.

I'm stumped on what could be causing this performance hit. 10 minutes is unacceptable. I don't think it's the stored procedure. Could it be the serialization due to the remote connection? Any thoughts on how I can track and correct down the culprit?

M.Babcock
  • 18,753
  • 6
  • 54
  • 84
John Russell
  • 2,177
  • 4
  • 26
  • 47

1 Answers1

3

The symptoms you are describing are those usually associated with an incorrectly cached query plan (due to parameter sniffing).

Ensure your statistics are up to date, and rebuild indexes if they are fragmented.

The canonical reference is: Slow in the Application, Fast in SSMS? An absolutely essential read.

Possible useful SO links:

Community
  • 1
  • 1
Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541
  • Thanks for the references. I have a feeling it is something along these lines. I'm going to spend some time reading the above links. I'll follow up with what I find. Thanks again. – John Russell Feb 06 '12 at 12:46