title: How to set a max run time / timeout for Power Query?
body: <p>Is there a way to set a max run time or a timeout factor in Power Query so that after a specified period the query would terminate itself regardless of whether it was successfully executed or not?</p>
  
  <p>This is important for me because I have built various queries at my workplace that usually run fine (as in I have been running it daily without issues for months and years) but occasionally, they would hang (likely because of clashing with another process on the server at that moment, when the server was under heavy load) and keep making read requests on the server <strong>indefinitely</strong> - One time IT have told me they logged more than 7 million reads from my machine into the database within a few hours. In cases, these have caused the servers to crash which leads to extensive downtime.</p>
  
  <p>So I would like to know if there is any setting, or any thing that I can build into the query itself to ensure it terminates after a certain period of time.</p>
  
  <p>I'm proficient with the M Power Query langue.</p>
  
  <p>Thanks.</p>
  
  <p><strong>[Update 1]</strong> 
  Thanks Alexis for the suggestion below regarding setting a CommandTimeout value when coding the connection. It's a great pointer.</p>
  
  <p>I'll try it out, do some tests and report back if it conclusively fixed the issue or not.</p>
  
  <p>But in the meantime, I've done a bit of digging into Microsoft's Power Query documentation and found that the CommandTimeout argument itself already has a default value of 10 minutes built into it, so theoretically even if we didn't specify that argument, the query should have terminated itself. But that wasn't the case. It ran for hours.</p>
  
  <p>I wonder if it is a bug with Excel version of Power Query? Because I do use Power Query within Power BI as well, and over there I haven't seen it crashing and hanging yet (admittedly I've been using the Excel version more frequently than I did Power BI).</p>
  
  <p>However, if anyone has any other suggestions on potential fixes for this problem,  that would be much appreciated. Thanks.</p>