JDBC Connection to SQL Server 2000 reset randomly on Solaris server

I have the following method being called in a Java EE web application.

public static void submitToPending()
{
    Db db;
    ResultSet rs;

    try
    {
        db = new Db("Database.properties");

        rs = db.issueQuery(getDescriptorList());

        while (rs.next())
        {
            db.insertApplicationData(rs.getString("Id"));
        }
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
    finally
    {
        db = null;
        rs = null;
    }
}

This is an abbreviated snippet of code I am running to insert about 40,000 new records into a SQL Server 2000 database. This code is executed from a JSP that is hosted on a Solaris 10 server in production. Prior to this year, this code only had to process about 18,000 records, and it worked flawlessly. This year there were some updates made and, to spare details, now processes roughly 40,000 records.

During development I test this on the same database used in production (as the record sets do not conflict) from my Windows PC, from a Tomcat server running inside of Eclipse. Everything works correctly, and all 40,000 or so records make it to the database.

When I installed the site to the production server and ran a test I noticed that over halfway through the process was failing, with the following exception message:

com.microsoft.sqlserver.jdbc.SQLServerException: The connection is closed. at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerConnection.checkClosed(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerStatement.checkClosed(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerResultSet.checkClosed(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerResultSet.next(Unknown Source) at (ClassNameOmittedToProtectTheInnocent.java:74)

The SQL Server is set to unlimited simulataneous connections, unlimited timeout. Assuming my code in class Db is OK (since it is working on the Windows side of things and, up until the data increase, had been performing well on the Solaris side) what are some ideas to start checking out?

I tried tracing the SQL Server to see if something was happening with the connections, but it appears to be alive even after the stack trace is written.

If I can provide any additional information, please let me know. I’ll do the best I can to help.

Answer

I’m suspicious of your setting your database and result set reference to null without closing them. I would explicitly close these (if you have a connection pool, closing a connection doesn’t actually close it, but acts as a signal to return the connection to the pool).

I’m guessing that you’re running into a resource limit such as the maximum number of open file descriptors per process, and the failure to close a result set/connection will be the source of this issue.

Leave a Reply

Your email address will not be published. Required fields are marked *