aspose file tools*
The moose likes JDBC and the fly likes Invalid state, the Connection object is closed. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Invalid state, the Connection object is closed." Watch "Invalid state, the Connection object is closed." New topic
Author

Invalid state, the Connection object is closed.

Marco Tulio Borges
Ranch Hand

Joined: Sep 14, 2004
Posts: 45
Hi there, Ranch folks! I've got a problem and just can't get an answer for that. Here it is:

Tomcat log says:
java.sql.SQLException: Invalid state, the Connection object is closed.
at net.sourceforge.jtds.jdbc.ConnectionJDBC2.checkOpen(ConnectionJDBC2.java:1305)


My app uses jTDS 1.1, SQL Server 2000 (sp3) and Tomcat 5.0.28 with J2SE 1.4.1 and I have a connection pool implementation "made by hand"... Not my own hands BTW. I don't have a clue why the connections are being closed. One thing is for sure: the app doesn't close them. Does anybody have a clue for me?


.: SCJP 1.4 (95%) / SCWCD 1.4 (91%) / SCBCD (77%) :.
"Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us." - Calvin
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3710
    
    5

Did you remember to call rs.next() before reading the first record of the data set? Or is this a non-issue?


My Blog: Down Home Country Coding with Scott Selikoff
Marco Tulio Borges
Ranch Hand

Joined: Sep 14, 2004
Posts: 45
Yes, I did... I think the connection is being closed by SQL Server or by my driver (jTDS 1.1) - can the driver do that?

But, what I really want to know is why is this happening so I can try to prevent it.
Alin Sinpalean
Greenhorn

Joined: Jun 02, 2005
Posts: 6
I think the connection is being closed by SQL Server or by my driver (jTDS 1.1) - can the driver do that?


The connection is most likely closed by you (read "your pool implementation") calling close() on it.

There's a very-very slight possibility that there's a communication error between the driver and SQL Server (either network or TDS protocol issue) and that's causing the connection to close, but I wouldn't bet on that. Try without the pool and if it works, then you know where the problem lies.

Alin,
The jTDS Project.
Marco Tulio Borges
Ranch Hand

Joined: Sep 14, 2004
Posts: 45
Originally posted by Alin Sinpalean:
The connection is most likely closed by you (read "your pool implementation") calling close() on it.

Hi, Alin! I read it and there's no calling to close() on my code or on the pool implementation.

Originally posted by Alin Sinpalean:
There's a very-very slight possibility that there's a communication error between the driver and SQL Server (either network or TDS protocol issue) and that's causing the connection to close, but I wouldn't bet on that.

I read something about the connection being closed by SQL Server in a forum (or mail list, I don't remember). I'm positive that neither my code (or the pool) is closing the connections (I've searched for close() calls all over it and in a bunch of different ways - with ctrl + alt + h in Eclipse, with search and with the "old-fashion" way: reading class after class).

Originally posted by Alin Sinpalean:
Try without the pool and if it works, then you know where the problem lies.

I've tried but I have other problems related. Creating and closing many connections (not using a pool) brings me performance issues and sometimes (after some time) I get a "Connection refused" (or something like that).
Don't know what else to do! I'm struggling with the DBAs to read the logs from SQL Server... Maybe these logs have a hint for me. Maybe.
[ November 10, 2005: Message edited by: MTulio Borges ]
Prashant Jain
Greenhorn

Joined: Aug 19, 2004
Posts: 29
drivers of SQL server can act erratic and there is every possibility that jTDS closes the connection on it's own. I know one thing for sure that MIcrosoft's driver was opeing a lot of implicit connections when I evaluted that one.

I am assuming that you are not closing the connection any where.If this be the case, If I were you I would try using another open source or data direct's trial version driver. See if this problem still persists.

ensure that connections are in a commited state. I also faced a sitiuation where by default auto commit was false.After releasing to the pool as well, I didnt achieve much.
Marco Tulio Borges
Ranch Hand

Joined: Sep 14, 2004
Posts: 45
Originally posted by Prashant Jain:
drivers of SQL server can act erratic and there is every possibility that jTDS closes the connection on it's own.

Yeah, it's a possibility. But I did not have considered it yet because I haven't seen nobody that uses jTDS with the same problem. I think Alin Sinpalean could help us with that. Is there any similar cases related at jTDS?
 
Don't get me started about those stupid light bulbs.
 
subject: Invalid state, the Connection object is closed.