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:
... 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 thedatasource
ordriver
configuration, remove thedatasource-class
from thedatasource
ordriver
configuration. This allows JBoss to utilize thejava.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 defaultjava.sql.Driver
connection mechanism), add one or more properties to thedatasource
configuration corresponding to theset<Property>(...)
methods defined by the Microsoft driver and remove theconnection-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 standardjava.sql.Driver
mechanism which is the default for JDBC 4 compliant drivers when creating non-XA connections. - When using a
datasource-class
, theconnection-url
property 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-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