0

I have had, more than once, the problem that a complex query, when executed through a SqlCommand from a .NET application, behaves differently performance-wise than a query that is executed in SSMS. When I encounter these issues, the SqlCommand is always slower than queries run in SSMS, against the same database. Most notable are execution times of 3 seconds vs 150 ms, and 30 seconds vs. 70 ms.

What issues does the SqlCommand have that make it slower than queries run in SSMS?

Alexander
  • 19,906
  • 19
  • 75
  • 162
  • what is the command?, are you passing parameters? – Lamak Aug 23 '17 at 14:33
  • You have to show something. Should we guess? Maybe parameter sniffing because you don't use `Paramaters.Add("@col", SqlDbType.Varchar).Value="foo"` but `AddWithValue("@col", "foo")`. Maybe because you have deadlocks that your application causes – Tim Schmelter Aug 23 '17 at 14:34
  • 1
    Your question has been discussed on StackOverflow at [here](https://stackoverflow.com/questions/2736638/sql-query-slow-in-net-application-but-instantaneous-in-sql-server-management-st) and [here](https://stackoverflow.com/questions/801909/why-is-some-sql-query-much-slower-when-used-with-sqlcommand). There's is also a dedicated [article from Erland Sommarskog](http://www.sommarskog.se/query-plan-mysteries.html), SQL MVP – Code Different Aug 23 '17 at 14:36

0 Answers0