1
votes

I'm using jTDS is an open source 100% pure Java (type 4) JDBC 3.0 driver for Microsoft SQL Server (2012).

Tomcat 7 - I have Connection Pool configuration below

<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/webapp">
    <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"/>
</Context>

Sometimes, I'm getting the below exception - Unable to get an connection from sql server. I don't know the reason why?

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

2
If connection error is showing up somethings then: 1. check if all the connections are used up when you get this error 2. check if any table is locked when you get this error. Also let me know what are the troubleshooting steps you have already triedRaghuveer
There are multiple applications used by sql server. What will be max limit of connection on sql server?arjun
The problem with when i able to connect specific table this error is occurring? Is that sounds table is locked? How to resolve this error. However, I need to get records from this table?arjun
Also, if you see the above datasource configuration, maxActive connections set to 100. Is that configuration is correct? If we reduce the maxActive connections will figure out this issue?arjun

2 Answers

3
votes

Probably Check the following conditions:

  1. Check whether the socket or the resource pool port is not closed before the execution of the SQL statement.
  2. Check whether connection is not reset by any other process
  3. Check whether the port is not being used by or locked other process or other execution.
  4. Check whether the there is any available port in the pool of connections.
0
votes

Finally I am able to find the reason for getting this error. It is because, After restarting the database server the tomcat server is not restarted (so it remains alive even at the time of restarting the database). Hence the connection in the pool gets invalid. So when the web page tries to create database connection for the first time this error prompts, and during the next attempt it will get valid connection from connection pool as the application server identifies its connections are invalid, so it gets a pool of new connections.