简体   繁体   中英

Entity Framework stored procedure over remote connection

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?

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM