Performance discrepancy in SQL Server Profiler between web query and the same query ran in SSMS

203 views Asked by At

I have a query that takes ~20x as long for SQL server to execute when it comes from a web request, as it does from when the exact same query is ran via SQL Server Management Studio

The following screenshot is from the SQL Server Profiler. The first two records relate to the receipt and execution of query that's come in via the web request, whilst the third record is the exact same query run from SSMS. Why would there be a such a huge difference between the two?

A point: The query is generated from LINQ. I took a copy of the generated SQL and ran it in SSMS to get these results.

enter image description here

1

There are 1 answers

0
laktak On

ARITHABORT is ON by default in SSMS and OFF by default for a SqlClient connection.

See if this solves your issue:

new SqlCommand("SET ARITHABORT ON", connection).ExecuteNonQuery();