Benjamin Schneider
Benjamin Schneider

Reputation: 57

Query 10 x faster in ASP.NET than in SSMS

I am currently analyzing the search function of a web application written in ASP.NET / VB. The search function on the home page requests the results from a web service that in turn executes an SQL query and sends back the results.

For analyzing the performance, I debugged the application locally and copied the query to SSMS for running it with SET STATISTICS TIME ON.

When I run the application and check the response time for the requests to my service in the browser's developer tools, they tend to be around 300ms. When I copy the exact same query to SSMS, set all the parameters manually (e.g. "DECLARE @SearchTerm VARCHAR = '%foobar%'"), the query runs for anywhere between 1500ms and 2000ms.

I have found countless mentions of queries running slower from an application, but nothing as to why the opposite might happen.

Has anyone had similar experiences in the past or found a possible explanation for this behavior?

Upvotes: 0

Views: 84

Answers (1)

benjamin moskovits
benjamin moskovits

Reputation: 5458

I have to guess because you have not included the query and its associated query plan. I would guess you are using different values for @SearchTerm (and others) for the query in SSMS versus the ASP page. The query had a query plan optimized for the first time you used it based on the parameters passed in and when you run it from SSMS it uses an inappropriate query plan (for the different paramaters being passed in).

Upvotes: 1

Related Questions