Query times out when executed from web, but super-fast when executed from SSMS

前端 未结 8 876
忘了有多久
忘了有多久 2020-11-27 02:57

I\'m trying to debug the source of a SQL timeout in a web application that I maintain. I have the source code of the C# code behind, so I know exactly what code is running.

8条回答
  •  不知归路
    2020-11-27 03:46

    If using Entity Framework you must be aware that query parameters for string values are sent to database as nvarchar by default, if database column to compare is typed varchar, depending on your collation, query execution plan may require an "IMPLICIT CONVERSION" step, that forces a full scan. I could confirm it by looking in database monitoring in expensive queries option, which displays the execution plan.

    Finally, a explanation on this behavior in this article: https://www.sqlskills.com/blogs/jonathan/implicit-conversions-that-cause-index-scans/

提交回复
热议问题