title: JTDS - java.sql.SQLException: I/O Error: Connection reset by peer: socket write error
body: <p>I'm using <code>jTDS</code> is an open source 100% pure <code>Java (type 4) JDBC 3.0</code> driver for <code>Microsoft SQL Server (2012)</code>.</p>
  
  <p><code>Tomcat 7</code> - I have Connection Pool configuration below</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Context antiJARLocking="true" path="/webapp"&gt;
      &lt;Resource name="jdbc/dbname" auth="Container" type="javax.sql.DataSource"
                 maxActive="100" maxIdle="30" maxWait="10000" removeAbandoned="true" removeAbandonedTimeout="60"
                 username="abc" password="abc" driverClassName="net.sourceforge.jtds.jdbc.Driver"
                 url="jdbc:jtds:sqlserver://localhost;databaseName=dbname;SelectMethod=Cursor"/&gt;
  &lt;/Context&gt;
  </code></pre>
  
  <p>Sometimes, I'm getting the below exception - Unable to get an connection from sql server. I don't know the reason why?</p>
  
  <blockquote>
    <p>java.sql.SQLException: I/O Error: Connection reset by peer: socket
    write error   at
    net.sourceforge.jtds.jdbc.TdsCore.executeSQL(TdsCore.java:1052)   at
    net.sourceforge.jtds.jdbc.JtdsStatement.executeSQLQuery(JtdsStatement.java:465)
      at
    net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(JtdsPreparedStatement.java:777)
      at
    org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)
      at      at
    java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
      at
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
      at java.lang.Thread.run(Thread.java:662) Caused by:
    java.net.SocketException: Connection reset by peer: socket write error
      at java.net.SocketOutputStream.socketWrite0(Native Method)  at
    java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
      at java.net.SocketOutputStream.write(SocketOutputStream.java:136)   at
    java.io.DataOutputStream.write(DataOutputStream.java:90)  at
    net.sourceforge.jtds.jdbc.SharedSocket.sendNetPacket(SharedSocket.java:671)
      at
    net.sourceforge.jtds.jdbc.RequestStream.putPacket(RequestStream.java:560)
      at
    net.sourceforge.jtds.jdbc.RequestStream.flush(RequestStream.java:508)
      at net.sourceforge.jtds.jdbc.TdsCore.executeSQL(TdsCore.java:1039)
      ... 8 more 17-Apr-2015 12:00:54 ERROR PatientProcessor:614 -
    SQLException java.sql.SQLException: Already closed.   at
    org.apache.tomcat.dbcp.dbcp.PoolableConnection.close(PoolableConnection.java:84)
      at
    org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.close(PoolingDataSource.java:181)
      at      at
    java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
      at
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
      at java.lang.Thread.run(Thread.java:662</p>
  </blockquote>