title: Azure Sql request limit reached although the number of connections is well below the resource limit
body: <p>We have a few Java applications that use a common Azure Sql database through JDBC. Each application has a pool of connections to that database. The number of connections in the pool is limited, so the total number of connections from all applications is well below the database's <a href="https://azure.microsoft.com/en-us/documentation/articles/sql-database-resource-limits/" rel="noreferrer">resource limits</a>.</p>
  
  <p>Lately we've been getting these types of exceptions quite frequently:</p>
  
  <blockquote>
    <p>com.microsoft.sqlserver.jdbc.SQLServerException: Resource ID : 1. The
    request limit for the database is 200 and has been reached. See
    '<a href="http://go.microsoft.com/fwlink/?LinkId=267637" rel="noreferrer">http://go.microsoft.com/fwlink/?LinkId=267637</a>' for assistance</p>
  </blockquote>
  
  <ul>
  <li>We've verified using a profiler that the applications don't open more connections than they are allowed.</li>
  <li>We've also verified that that the correct number of applications is running, so the number of connections should be below the resource limit.</li>
  <li>One odd thing we've noticed was that <code>sp_who</code> shows a large number of connections whose <code>Login</code> column is empty:
  <a href="https://i.stack.imgur.com/hhaKq.png" rel="noreferrer"><img src="https://i.stack.imgur.com/hhaKq.png" alt="enter image description here"></a></li>
  </ul>
  
  <p>Any guesses as to what could be the cause of these errors?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>One theory we have has to do with Sql Server's <a href="https://msdn.microsoft.com/en-us/library/ms189094.aspx" rel="noreferrer">MaxDOP</a> parameter.</p>
  
  <p>Apparently, if this parameter is above 1, it's possible for Sql Server to use more than one worker thread per query. We think that those rows in <code>sp_who</code> without a <code>Login</code> value correspond to such additional worker threads used by one of the connections. That way, there could be (much) more worker threads than connections, so even though the number of connections is limited, we're saturating all worker threads.</p>
  
  <p><strong>Edit2:</strong></p>
  
  <p>Apparently Azure Sql's default Max Parallelism is set to 0 (unlimited), and can be changed only via a <a href="https://stackoverflow.com/a/33113280/3199595">support ticket</a>.</p>
  
  <p><strong>Edit3:</strong></p>
  
  <p>One more piece of evidence. We've executed <code>SELECT * FROM sys.resource_stat</code> on the master database. We're seeing <code>max_worker_percent</code> hit 100% from time to time. We really are saturating the worker threads.</p>