Connection timeout on query on large table

后端 未结 4 2030
难免孤独
难免孤独 2021-01-04 04:08

I have a problem with a script timing out while fetching data form a query on large table.

The table have 9,521,457 rows.

The query I\'m trying to preform is

相关标签:
4条回答
  • 2021-01-04 04:55
    command.CommandTimeout = int.MaxValue;
    

    If you know more exactly which number to insert, do that. If you set it to int.MaxValue, you are removing a security barrier.

    0 讨论(0)
  • 2021-01-04 05:03
    command.CommandTimeout = 2147483;
    

    The largest value for a MySQL command timeout is the largest value for a 32 bit integer, in milliseconds, 2147483647. But in C# the CommandTimeout property is in seconds, not milliseconds, so any higher than 2147483 will result in an exception.

    Although this is not infinite, it is 24 days, 20 hours, 31 minutes, and 23 seconds, which would hopefully meet your need.

    Setting the value to 0 did not work for me. The CommandTimeout property would not retain the value of 0 and kept auto-changing back to 30.

    Setting the value to -1 did seem to work, but I didn't test it enough to be certain that a timeout would never occur.

    Safest option: go with 2147483.

    0 讨论(0)
  • 2021-01-04 05:05

    Add an index on the customerId column.

    0 讨论(0)
  • 2021-01-04 05:15

    Set the CommandTimeout on the command object

    var command = connection.CreateCommand();
    command.CommandTimeout = 0;
    //zero specifies never timeout. 
    //Any number greater than zero is the number of seconds before 
    //the command will time out.
    
    0 讨论(0)
提交回复
热议问题