Why is some sql query much slower when used with SqlCommand?

后端 未结 4 2057
长情又很酷
长情又很酷 2020-11-30 05:17

I have a stored procedure that executes much faster from Sql Server Management Studio (2 seconds) than when run with System.Data.SqlClient.SqlCommand (times out

4条回答
  •  庸人自扰
    2020-11-30 05:27

    We had a similiar issue, where a query would complete in 2 seconds in SSMS and take more than 90 seconds when called from a .NET client (we wrote several VB/C# apps/sites to test it.)

    We suspected that the query plan would be different, and rewrote the query with explicit looping ("inner loop join" and "with index") hints. This solved the problem.

提交回复
热议问题