title: Sql Server JDBC Connection Reset Error : Only on Amazon EC2
body: <p><strong>Context: The Cloud</strong></p>
  
  <p>We have a java-based web application that we normally host on our own servers. Recently we used Amazon Web Services (AWS EC2) cloud to host an instance.</p>
  
  <p>This "cloud setup" matches our typical "on site" setup: one server for the app server, another server for the database server. (Several app servers point to the same database server)</p>
  
  <p><strong>The problem</strong>
  In this cloud setup, we receive intermittent "connection reset by peer errors" between the database and the jdbc driver, where at (seemingly) random intervals and at random points in the codebase, the database connection fails.</p>
  
  <p>Here are a few error excerpts for the log</p>
  
  <p><strong>Stack Trace Example 1:</strong></p>
  
  <pre><code>at com.participate.pe.genericdisplay.client.taglib.GenDisplayViewTag.doStartTag(GenDisplayViewTag.java:77)
      ... 75 more
  Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The connection is closed.
      at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:170)
      at com.microsoft.sqlserver.jdbc.SQLServerConnection.checkClosed(SQLServerConnection.java:304)
      at com.microsoft.sqlserver.jdbc.SQLServerConnection.getMetaData(SQLServerConnection.java:1734)
      at org.jboss.resource.adapter.jdbc.WrappedConnection.getMetaData(WrappedConnection.java:354)
  </code></pre>
  
  <p><strong>Stack Trace Example 2</strong></p>
  
  <pre><code>    at java.lang.Thread.run(Thread.java:619)
  Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Connection reset
      at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1368)
      at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1355)
      at com.microsoft.sqlserver.jdbc.TDSChannel.read(IOBuffer.java:1532)
      at com.microsoft.sqlserver.jdbc.TDSReader.readPacket(IOBuffer.java:3274)
      at com.microsoft.sqlserver.jdbc.TDSCommand.startResponse(IOBuffer.java:4437)
      at com.microsoft.sqlserver.jdbc.TDSCommand.startResponse(IOBuffer.java:4389)
      at com.microsoft.sqlserver.jdbc.SQLServerConnection$1ConnectionCommand.doExecute(SQLServerConnection.java:1457)
      at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4026)
      at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1416)
      at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectionCommand(SQLServerConnection.java:1462)
      at com.microsoft.sqlserver.jdbc.SQLServerConnection.setAutoCommit(SQLServerConnection.java:1610)
      at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.checkTransaction(BaseWrapperManagedConnection.java:429)
  </code></pre>
  
  <p><strong>Technical Environment</strong></p>
  
  <ul>
  <li>Jboss 4.2.2.GA (Jboss-Web 2.0/ Tomcat 6)</li>
  <li>MSSQL 2005 2.0 jdbc driver</li>
  </ul>
  
  <p><strong>Some points</strong></p>
  
  <ul>
  <li>We have <em>never</em> seen this problem in
  our own environment (i.e. own data centers) running the application for several years</li>
  <li>This led me to conclude "something funny is going on with Amazon network environment". I may be wrong/missing something/etc.</li>
  <li>This problem only occurs with our application. We have other java and php applications which have not had this problem. The other java application uses a different jdbc driver (jtds, afaik)</li>
  <li>It doesn't seem like a simple connection timeout</li>
  </ul>
  
  <p><strong>Questions</strong></p>
  
  <p>-Has anyone seen this before?
  -If it's an EC2 "known issue", can we configure our way around the problem (i.e. make sure everything is on its own subnet or virtual private cloud (vpc) ?
  -Any jdbc driver settings to get past this problem?</p>
  
  <p>** Update **
  I've extended and increased the bounty on this question.</p>
  
  <p>On  extra bit of information: the two virtual servers (database and application server) were on different subnets--i.e. one hop between the two servers. </p>
  
  <p>In a non-cloud environment we have "zero hops" bewtewn the two servers.</p>
  
  <p>Our hosting admins said we had no control over the subnets of our EC2 instances. This made me wonder if virtual private cloud would help. </p>
  
  <p>thanks in advance</p>
  
  <p>will</p>