1

When I use dbContext.spGetData(param1, param2), it goes long to get record from db. But the same stored procedure with same parameters doesn't take time in query window. Why it takes too much time via linq?

No doubt linq is slow than query running in query window, but in my case it goes too long.

running stored proc in query window take 4 second.
calling the same stored proc in application takes above 3 minutes.
Lali
  • 2,816
  • 4
  • 30
  • 47
  • 1
    Run the SQL Server Profiler and capture exactly what is being sent to SQL Server from the c# code. – user957902 May 14 '14 at 11:51
  • How many records returned the SP? Do you run the SSMS on the same machine as SQL Server but your own client in another machine (may be a network issue). – Hamlet Hakobyan May 14 '14 at 11:57
  • Does your SP use anything like persisted indexed columns or xml columns? Different `SET` options can **drastically** change the way something performs, and SSMS and ADO.NET have different `SET` options – Marc Gravell May 14 '14 at 11:58
  • Over 2000 records. DB is on another server, I am connecting my sqlserver to the instance that is on server. Also application is on my local PC. Both computers are on the same server. – Lali May 14 '14 at 11:59
  • Have closed as duplicate. This issue is almost always caused by the same problems. Please reopen if this does not solve your problem and specify what you have already done to solve it. This should include a reason why the linked duplicate is not duplicate. – usr May 14 '14 at 12:07

1 Answers1

1

Please read the canonical reference: Slow in the Application, Fast in SSMS?

Most likely cause is out of date statistics, fragmented indices or parameter sniffing (or combination thereof).

Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541