Question

Here is the famous SQLServerException error message:

Error: "Address already in use: connect. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port.".

But, it is not happening in the first calls. All the DAO methods, use a unique method to get connections and all of them close the connection when they are done with database.

When these number of calls exceeds, that method cannot get connection any more and throw SQLServerException.

There is something in the server configuration not database. Because, I tried the same scenario with different database, and the same error happens. But, when I changed the server (web server), I don't get the error.

There are tens of solution for this message, but all of them are related to firewall, or database connection. My problem is why sometimes it works, sometimes it doesn't?

Here is the body of method that get connections:

Connection connection = null;
try {
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

connection = DriverManager.getConnection(DB_CONNECTION_STRING, USERNAME, PASSWORD);
} catch (ClassNotFoundException e) {
    DbmgrLogger.logger.error("fail creating the sql connection", e);
} catch (SQLException e) {
    DbmgrLogger.logger.error("fail creating the sql connection", e);
}
return connection;

Update: Here is the stack:

at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:171)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1033)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:817)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:700)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:842)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
Was it helpful?

Solution

That error means that the port you are trying to use is already used by something else (Most likely the same application that didn't close the resource?)

Adding comment as answer for closing purposes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top