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
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, and the listed hostname/port (localhost:1443 in this log) is not correct for the database.
... 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-classproperty has been specified unintentionlly in thedatasourceordriverconfiguration, remove thedatasource-classfrom thedatasourceordriverconfiguration. This allows JBoss to utilize thejava.sql.Driverimplementation specified by the underlying driver. -
If the use of the
datasource-classis required/intentional (i.e. if you cannot utilize the defaultjava.sql.Driverconnection mechanism), add one or more properties to thedatasourceconfiguration corresponding to theset<Property>(...)methods defined by the Microsoft driver and remove theconnection-urlproperty. For example:<connection-property name="URL">jdbc:sqlserver://myhost:1433</datasource-property>
Root Cause
-
The issue may be due to specification of a
datasource-classwhen defining a non-XA pool.<datasource-class>com.microsoft.sqlserver.jdbc.SQLServerDataSource</datasource-class>- The use of an implementation of
javax.sql.DataSourcerequires significantly different configuration from the standardjava.sql.Drivermechanism which is the default for JDBC 4 compliant drivers when creating non-XA connections. - When using a
datasource-class, theconnection-urlproperty is ignored and no JDBC url is supplied, hence the exception.
- The use of an implementation of
- Note that the web console automatically (incorrectly) adds a
datasource-classattribute 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