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

前端 未结 8 835
忘了有多久
忘了有多久 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:58

    This answer includes a way to resolve this issue:

    By running the following commands as administrator on the database all queries run as expected regardless of the ARITHABORT setting.

     DBCC DROPCLEANBUFFERS
     DBCC FREEPROCCACHE
    

    Update

    It seems that most people end up having this problem occur very rarely, and the above technique is a decent one-time fix. But if a specific query exhibits this problem more than once, a more long-term solution to this problem would be to use Query Hints like OPTIMIZE FOR and OPTION(Recompile), as described in this article.

    0 讨论(0)
  • 2020-11-27 04:00

    I have the same problem when trying to call SP from SMSS it took 2 sec, while from the webapp (ASP.NET) it took about 3 min.

    I've tried all suggested solutions sp_recompile, DBCC FREEPROCCACHE and DBCC DROPCLEANBUFFERS but nothing fixed my problem, but when tried parameter sniffing it did the trick, and worked just fine.

    0 讨论(0)
提交回复
热议问题