-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: java.sql.SQLException: Connection reset by peer
PostPosted: Mon Apr 24, 2006 4:33 am 
Beginner
Beginner

Joined: Mon Dec 26, 2005 4:55 pm
Posts: 28
Hi,

I have developed an application (with hibernate) with the backend database being a MS SQL Server. I have deployed this application on Resin over a week ago. However one of my friends reported that he had an exception thrown to him (something I left on purpose at the moment). The exception thrown was:
Code:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Connection
reset by peer: socket write error

Now to make the system run again I just restarted the resin service, and everything worked fine. However I know this is not the solution for the problem, and therefore I did some extra research using Google and the many forums out there (including this one).

What I found out is that this exception is usually thrown because of a network failure. Now this is hardly possible in my scenario because both database and application servers (in this case resin / IIS) are both on the same computer.

Now I have the feeling that this could be because of unclosed connections. Is it possible that too many connections are being created, and therefore that exception is being thrown?

On a post (in this same forum) it seems to be blame DBCP for this, and says that proxool is a better tool. But this post is dated 26th August 2003. Now I am using Hibernate 3.0 and do not know if this is till the point. Other posts say it is something with Oracle, and others with JBoss (but I am not using both), and most of the others I found are un answerd!

I would greatly appreciate any comments, even if you suggest me ways I how I can cornet this problem and see why it is coming out. My only problem (and fear) is that it seems to come out over a long period of time (this is why I am feeling as if it is some kind of unclosed connection :S)

Thanks and regards,
Sim085

ps: this is all the stack trace (do not know it would help):

Code:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Connection
reset by peer: socket write error
   at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
   at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
   at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
   at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.submitRequest(Unknown Source)
   at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.execute(Unknown Source)
   at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
   at com.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source)
   at com.microsoft.jdbc.base.BasePreparedStatement.executeQuery(Unknown Source)
   at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139)
   at org.hibernate.loader.Loader.getResultSet(Loader.java:1669)
   at org.hibernate.loader.Loader.doQuery(Loader.java:662)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
   at org.hibernate.loader.Loader.doList(Loader.java:2150)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
   at org.hibernate.loader.Loader.list(Loader.java:2024)
   at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1492)
   at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:298)
   at com.school.dao.impl.AccountDAO.findByUserName(Unknown Source)
   at com.school.service.impl.BaseAccountService.checkUserNameAvailable(Unknown Source)
   at com.school.forms.RegisterForm.validate(Unknown Source)
   at com.school.actions.RegisterUserAction.doCreate(Unknown Source)
   at com.school.actions.RegisterUserAction.executeAction(Unknown Source)
   at com.school.actions.RegisterUserAction.execute(Unknown Source)
   at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
   at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
   at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
   at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:154)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:92)
   at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:106)
   at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:178)
   at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:229)
   at com.caucho.server.hmux.HmuxRequest.handleRequest(HmuxRequest.java:419)
   at com.caucho.server.port.TcpConnection.run(TcpConnection.java:389)
   at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:492)
   at com.caucho.util.ThreadPool.run(ThreadPool.java:425)
   at java.lang.Thread.run(Thread.java:595)


Top
 Profile  
 
 Post subject: Mybe solved?
PostPosted: Mon Apr 24, 2006 4:50 am 
Beginner
Beginner

Joined: Mon Dec 26, 2005 4:55 pm
Posts: 28
Hi (again),

I think I may have trapped the problem, and know how to solve it, but please do confirm me if my suspicions are correct since I am not expert, and this is only my first attempt to hibernate.

I think my problem is in my service layer, the one that takes calls the dao object.

At the moment I call a dao object to save an object as follows:

Code:
EmploymentDAO dao = DAOFactory.DEFAULT.getEmploymentDAO();
Transaction transaction = dao.getSession().beginTransaction();
Employment returnEmployment = dao.makePersistent(employment);
transaction.commit();
dao.getSession().close();
return returnEmployment;


No try catch, no finally. Now I can see the problem that could come from this. Since, if something goes wrong, then the session remains open right! Microsoft SQL Server would still close it after some time, and this could lead to the problem (I read this on another forum) that my application thinks there is an open session, while the database says no, tries to use that session again … (maybe, not sure of that)!

I thought of changing the code as follows:

Code:
EmploymentDAO dao = DAOFactory.DEFAULT.getEmploymentDAO();
Transaction transaction = null;
Employment returnEmployment = null;
try{
   transaction = dao.getSession().beginTransaction();
   returnEmployment = dao.makePersistent(employment);
   transaction.commit();
}
catch(Exception e){
         
   transaction.rollback();
}
finally{
   dao.getSession().close();   
}      
      
return returnEmployment;


Please give me any opinion on this one, since would not like to be doing something stupid :$

Regards,
Sim085


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.