title: using JDBC Connection Pool with SQL Azure Database gives "Error in allocating a connection"
body: <p>I have a Java EE web application deployed on glassfish 3.1.1 which I want to host on Windows Azure.</p>
  
  <p>The application uses hibernate as jpa.</p>
  
  <p><br>
  I defined a JDBC Connection Pool for the Azure database.</p>
  
  <p>(basically, these are the defaults)</p>
  
  <p>Initial and Minimum Pool Size: 8 Connections</p>
  
  <p>Maximum Pool Size: 32 Connections</p>
  
  <p>Pool Resize Quantity: 2 Connections</p>
  
  <p>Idle Timeout: 300 Secconds</p>
  
  <p>Max Wait Time: 60000 Milliseconds</p>
  
  <p><br></p>
  
  <p>Additional Properties:</p>
  
  <p>User: user@serverName</p>
  
  <p>ServerName: serverName.database.windows.net</p>
  
  <p>Password: myPass</p>
  
  <p>databaseName: mydatabase</p>
  
  <p><br></p>
  
  <p>If i ping it from the glassfish interface it works, so the properties I provide are ok.</p>
  
  <p>Setting the new jdbc connection pool (the one for azure) resulted in the tables being created on the sql azure database (i have "hibernate.hbm2ddl.auto" set to update) - so there isn't a problem with the database connection/parameters.</p>
  
  <p>If the application uses the database immediately after the server started, all goes well (it can retrieve/store data) </p>
  
  <p>When the application tries to use the database after being idle for a while, I get this:</p>
  
  <p><a href="http://pastebin.com/xZmE1er2" rel="nofollow">link to exception</a></p>
  
  <p>If I flush the connection (from glassfish admin) it starts to work again, until it goes idle for a period of time.</p>
  
  <p>So basically, as long as it executes database operations all works well, but if there are no database operations for a while, the next db operation will result in that exception.</p>
  
  <p>I've google'd this and it seems to have something to do with the azure database server closing the idle connection, but I couldn't find a solution for the problem.</p>
  
  <p>I never had this problem when using PostgreSql</p>