How do I increase the timeout period for my stored procedure call (see error)?

后端 未结 6 1062
时光取名叫无心
时光取名叫无心 2021-02-14 13:01
 Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
Description: An unhandled exception occurred during t         


        
相关标签:
6条回答
  • 2021-02-14 13:22

    Then add it in the connection string:

    server={servername};database={dbname};uid={username};pwd={password};Connect Timeout=600
    
    0 讨论(0)
  • 2021-02-14 13:26

    Perhaps this doesn't apply, but I think it should be mentioned none the less. The default CommandTimeOut is 30 seconds. This should be plenty of time for any actions that are happening in 99.9% of a web application. Unless you are absolutely sure that the action should take longer than that, you should spend your time trying to optimize the sql so that it returns in <30 seconds. Proper indexing is a good place to start for that.

    0 讨论(0)
  • 2021-02-14 13:27

    +1 to Al because 30 seconds should be plenty. Making the timeout period longer is really only a bandage to the underlying problem.

    In my experience the stored proc is too expensive 90% of the time. When I was reviewing these errors last, I had a general rule of thumb that no stored proc cost more than 1.00. The more expensive they are, the greater the risk we had of blocking and generating these exceptions.

    0 讨论(0)
  • 2021-02-14 13:33

    the used query wasn't optimized for the amount of data. In our case we have purged unused data, but an better option should be optimizing the query or to have a look at the housekeeping. After the action we didn't receive the error anymore. Ofcourse it depends on the situation in which you receive this error and if this solution will help you out.

    0 讨论(0)
  • 2021-02-14 13:40

    You can accomplish this by adding "Connect Timeout=90" to the connection string. If your query is taking longer than 30 seconds though you should really consider optimizing the query somehow. Indexes may need to be added or a view might need to be created, etc.

    Edited to correct issue pointed out by @Stijn comments.

    0 讨论(0)
  • 2021-02-14 13:41

    You can raise the timeout period on the command by setting the SqlCommand.CommandTimeout property.

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