Error com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost, port 1433 has failed using a non-XA SQL Server datasource

Solution Verified - Updated -

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP) 7.2
  • Microsoft SQL Server (non-XA datasource)

Issue

  • The following exception is raised when obtaining a connection from a non-XA Microsoft SQL Server datasource:

    ... Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall."
    

Resolution

Disclaimer: Links contained herein to external website(s) are provided for convenience only. Red Hat has not reviewed the links and is not responsible for the content or its availability. The inclusion of any link to an external website does not imply endorsement by Red Hat of the website or their entities, products or services. You agree that Red Hat is not responsible or liable for any loss or expenses that may result due to your use of (or reliance on) the external site or content.

One of the following may resolve the issue

  • If a datasource-class property has been specified unintentionlly in the datasource or driver configuration, remove the datasource-class from the datasource or driver configuration. This allows JBoss to utilize the java.sql.Driver implementation specified by the underlying driver.
  • If the use of the datasource-class is required/intentional (i.e. if you cannot utilize the default java.sql.Driver connection mechanism), add one or more properties to the datasource configuration corresponding to the set<Property>(...) methods defined by the Microsoft driver and remove the connection-url property. For example:

        <connection-property name="URL">jdbc:sqlserver://myhost:1433</datasource-property> 
    

Root Cause

  • The issue may be due to specification of a datasource-class when defining a non-XA pool.

        <datasource-class>com.microsoft.sqlserver.jdbc.SQLServerDataSource</datasource-class>
    
    • The use of an implementation of javax.sql.DataSource requires significantly different configuration from the standard java.sql.Driver mechanism which is the default for JDBC 4 compliant drivers when creating non-XA connections.
    • When using a datasource-class, the connection-url property is ignored and no JDBC url is supplied, hence the exception.
  • Note that the web console automatically (incorrectly) adds a datasource-class attribute in early patch levels of JBoss EAP 7.2 (and in the un-patched GA).

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments