Wildfly Datasource via VPN to MS SQL Server - java

currently, I am facing some odd behavior.
I have a Java EE Web Application that I am deploying to a wildfly server. This Java EE Application needs a database to which we need to connect via vpn. We are using OpenVPN. When I am using SSMS I have no problems connecting to the database. When I am using pure JDBC, there also is no problem.
But if I am creating a datasource in wildfly (and I am using the exact same jdbc connection url) it does not working. I am using the wildfly admin ui and click the test-button.
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 10.1.115.51, port 1433 has failed. Error: "connect timed out. 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.".
I mean, the stack trace is pretty clear. However, the connection should be possbile as I connect via ssms and pure jdbc. Just wildfly datasource is not working.
Furhtermore, I have installed a MS SQL Server on the same mashine the wildfly is running on and using this MS SQL instance the datasource is working fine.
The jdbc url connection url is the following:
jdbc:sqlserver://< ip >:1433;databaseName=projdat;user= ** ;password= **
I have compared the jdbc url connection urls multiple times. Both in the pure jdbc and in the datasource they are the same.
Does anybody have any ideas? Is possible that I need to configure openvpn in a special way that wildfly can connect or do I need to configure Wildfly to be able to connect via vpn. Or do I have to configure the MS SQL Server in special way?
Version of MS SQL Server: 12
Version Wildfly: 19.0.0.Final
SQL Server driver: mssql-jdbc-8.2.2.jre8.jar
I apreciate any hint or advise.

Apparently, I was using an older version of Wildfly (in fact, it was wildfly 16). After I upgraded to Wildfly 19, it is now working. However, I have no clue why it was not working with wildfly 16.

Related

Not able to connect to Postgres server via java application

In one of my project, we are trying to connect to Postgres server via Java application. It gives an error when try to open connection. Stack trace is below -
{"timestamp":"2016-03-17T06:57:18.853Z",
"level":"ERROR",
"thread":"main",
"logger":"com.abc.messaging.status.configuration.ValidateDatabaseConfiguration",
"message":"Failed to initialize data source: \n
### Error opening session. Cause: java.lang.NullPointerException\n
### Cause: java.lang.NullPointerException","context":"default"}
While we have tried following -
Ping db server from application server - it's successful
Telnet db server and port (from app server)- it's also successful
We also tried a simple python script that connects to postgre server. It also connects to db successfully.
We then moved back to our staging server and tried to connect production db server from there. This is also done successfully.
We tried connecting staging db server from production app server, which also we COULDN'T.
We are assuming that we don't have any issue in our application. This is because, from staging server, application can connect to both staging db and production db. There by, it must be some application server issue or something.
PostgreSQL version - Production - 9.4.5 Staging - 9.4.4
Java version - 1.8.31
Any kind of help would be much appreciated.
Thanks in advance.

SQLServer authentication exception by jdbc

i'm trying to connect to a newly installed SQLServer instance by my java application using jdbc.
When i try to open a connection the server return this error:
com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'sa'.
Error Stack trace:
com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'sa'. at
com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerE‌​xception.java:197) at
com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:246)
I've already enabled "SQL Server and Windows Authentication mode" option.
I also tried to connect to the database server with SquirreL but i had the same problem, but with SQL Server Management Studio i can connect to the db.
I have a SQLServer 2008 R2 express, jdk 6u41 and sqljdbc4.jar JDBC connectors.
I've tried the same application in an environment with SQLServer 2008 R2 express, jdk 6u33 and sqljdbc4.jar JDBC connectors and it work fine.
Are there some SQL server configuration that i need to modify?
I think, you have configured the SQL Server in Windows Authentication mode on the time of installation but, changing the settings in the program would not change it from Windows Authentication mode.
Can you do one thing? Remove the SQL Server 2008 and all related programs from your machine and install a fresh copy, this time with SQL Server Authentication. It will work...

connecting to local MS SQL Server

I have a local MS SQL Server and I am trying to connect to it using JTDS in java. Here is the connection string:
Class.forName("net.sourceforge.jtds.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/stock","sa","password");
And the server properties:
name: USER-PC\SQLEXPRESS
root directory: c:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL
I am getting a Exception in thread "main" java.sql.SQLException: Network error IOException: Connection refused: connect error.
How can I remedy this?
Check the following:
You have enabled mixed mode security, i.e. so you can connect with username/password (rather than using Windows authentication)
The TCP/IP protocol is enabled. Open SQL Server Configuration Manager, then in SQL Server Network config select Protocols and Enable TCP/IP.
Try passing just one String to getConnection using this format:
DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/stock;instance=SQLEXPRESS;user=sa;password=password")
If you are using this format (naming the instance) then the SQL Server Browser service needs to be running (in Services). If this is greyed out then the Service is probably disabled, so enable it and then start it.
Port 1433 is the port used by the default instance. You're using SQLEXPRESS, which is a named instance. Your connection string should include something like:
sqlserver://localhost\SQLEXPRESS
SQL Server Browser service is disable by default. If you're developing .Net app, you do not need to start SQLBrowser, but if you're using JTDS in java, you will need it started.

Netbean Service with Sql Server 2008

I have been trying to connect netbean service for database explorer with Microsoft SQL Server JDBC Driver 3.0 but unsuccessful always.The zipped jdbc driver has two jars I tested it with sqljdbc but it says that is is not compatible with java 1.7 so I tried it with sqljdbc4 and now it shows following error:
I have enable TCP/IP connection to the server.
What is the right way to connect netbean service with sql server 2008?
I got the solution to this problem actuall you should use the port 57634 for TCP/IP connections. Well you can change the port if you want by going to :
Configuration Manager -> Protocols for SQL SQLEXPRESS > Properties of TCP/IP. In the IP Addresses tab, set the TCPPort in section IPAll to 1433.

The Network Adapter could not establish the connection when connecting with Oracle DB

When trying to connect with a remote Oracle database via JDBC I receive the following exception:
java.sql.SQLRecoverableException: IO-fout: The Network Adapter could not establish the connection
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:419)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:536)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:228)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:521)
at java.sql.DriverManager.getConnection(DriverManager.java:322)
at java.sql.DriverManager.getConnection(DriverManager.java:358)
The following is my set-up:
Database: Oracle 10g Release 2 Standard Edition
JDBC library: ojdbc6.jar
JDBC driver: oracle.jdbc.driver.OracleDriver
JDBC URL: jdbc:oracle:thin:#9.2.2.2:1521:ORCL where ORCL is database's SID
JDBC User/pwd: Correct username / password
Strange about this problem is that the connection works just fine when I work from work. When I try to connect however from home via an AT&T VPN connection, it doesn't work.
I have confirmed that I can reach the IP address and have also telnetted the ip on port 1521, which works just fine. Connecting to the datasource from a local WebLogic Application Server also works alright. Furthermore, when trying to connect to the database via sqldeveloper I can also reach the database.
I need to reach the database however from a standalone application (for testing purposes). Does anyone have an idea why this problem occurs? And whether there are alternatives for connecting to a remote Oracle Database, alternatives which sqldeveloper and weblogic perhaps use?
Here's an excerpt of the code attempting to connect with the database:
public static void main(String args[]) throws ClassNotFoundException, SQLException {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:#9.2.2.2:1521:ORCL", "user", "pwd");
}
When a client connects to an Oracle server, it first connnects to the Oracle listener service. It often redirects the client to another port. So the client has to open another connection on a different port, which is blocked by the firewall.
So you might in fact have encountered a firewall problem due to Oracle port redirection. It should be possible to diagnose it with a network monitor on the client machine or with the firewall management software on the firewall.
If it is on a Linux box, I would suggest you add the database IP name and IP resolution to the /etc/hosts.
I have the same error and when we do the above, it works fine.
Take a look at this post on Java Ranch:
http://www.coderanch.com/t/300287/JDBC/java/Io-Exception-Network-Adapter-could
"The solution for my "Io exception: The Network Adapter could not establish the connection" exception was to replace the IP of the database server to the DNS name."
I had similar problem before. But this was resolved when I started using hostname instead of IP address in my connection string.

Categories

Resources