Increasing the Command Timeout for SQL command

前端 未结 5 1740
死守一世寂寞
死守一世寂寞 2020-12-08 09:04

I have a little problem and hoping someone can give me some advice. I am running a SQL command, but it appears it takes this command about 2 mins to return the data as there

相关标签:
5条回答
  • 2020-12-08 09:40

    it takes this command about 2 mins to return the data as there is a lot of data

    Probably, Bad Design. Consider using paging here.

    default connection time is 30 secs, how do I increase this

    As you are facing a timeout on your command, therefore you need to increase the timeout of your sql command. You can specify it in your command like this

    // Setting command timeout to 2 minutes
    scGetruntotals.CommandTimeout = 120;
    
    0 讨论(0)
  • 2020-12-08 09:44

    Setting command timeout to 2 minutes.

     scGetruntotals.CommandTimeout = 120;
    

    but you can optimize your stored Procedures to decrease that time! like

    • removing courser or while and etc
    • using paging
    • using #tempTable and @variableTable
    • optimizing joined tables
    0 讨论(0)
  • 2020-12-08 09:44

    Setting CommandTimeout to 120 is not recommended. Try using pagination as mentioned above. Setting CommandTimeout to 30 is considered as normal. Anything more than that is consider bad approach and that usually concludes something wrong with the Implementation. Now the world is running on MiliSeconds Approach.

    0 讨论(0)
  • 2020-12-08 09:45

    Add timeout of your SqlCommand. Please note time is in second.

    // Setting command timeout to 1 second
    scGetruntotals.CommandTimeout = 1;
    
    0 讨论(0)
  • 2020-12-08 09:49

    Since it takes 2 mins to respond, you can increase the timeout to 3 mins by adding the below code

    scGetruntotals.CommandTimeout = 180;
    

    Note : the parameter value is in seconds.

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