Friday, May 29, 2015

RDBMS -- java.sql.SQLException: Io exception: The Network Adapter could not establish the connection

I think it is worth write about the problem regarding a Sql Server Connection..
The issue were encountered in a custom code which was suppose to run on an EBS 12.2 Application Tier..It was thought of an sql server connection issue when it was first escalated to me..

I have requested the code block that the developer was complaning about.
The code was something like the following;
Note that: Because we are in Oracle World , also because we are working on Oracle Application in this story, we use java for these kind of stuff.

This method was there in a Custom class stored in Application Server..

public Connection getMSQLServerConnection()
throws Exception
{
Class.forName("net.sourceforge.jtds.jdbc.Driver");
return DriverManager.getConnection("jdbc:jtds:sqlserver://SOME_IP:1433/SOME_DB_NAME;", "erman", "password123");
}

So method was correct and I could reach the sqlserver's port using telnet.
telnet sqlservers_ip sqlservers_port..
There werent any classpath issues ..

The error produced was "java.sql.SQLException: Io exception: The Network Adapter could not establish the connection" and it was weird.. According to this error, there must have been a connection problem somewhere..

With this in mind, I requested the full error stack and realized the problem when I saw that;

java.sql.SQLException: Io exception: The Network Adapter could not establish the connection at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:124) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:161) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:273) at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:327) at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:360) at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:150) at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:31) at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:595) at java.sql.DriverManager.getConnection(DriverManager.java:571) at java.sql.DriverManager.getConnection(DriverManager.java:215) at erman.oracle.apps.datatransfer.ErmanMSSQLViewDataTransfer.getOracleConnection(ERMANSSQLViewDataTransfer.java:48) at erman.oracle.apps.datatransfer.ErmanMSSQLViewDataTransfer.transferData(MSSQLViewDataTransfer.java:75) at erman.oracle.apps.datatransfer.ErmanMSSQLViewDataTransfer.main(ErmanMSSQLViewDataTransfer.java:298)
The issue was there and it was not like it seemed..
The driver used was OracleDriver, so it was not an sql driver at all.
If it would be an sql driver, it must have been there as something like: ..jtds.jdbc.Driver....

So, the problem was actually an Oracle Connection problem..
Later turned out that; there was another method in the same class and this method was used to connect to an Oracle database.. 
The class was a DataTransfer class , so it was designed to create its connections to both Oracle and SqlServer databases.. It was trying to create the connections and then transfer the data between the databases using these connections..

As for the solution;

When I analyzed the Oracle connection method, I saw that the IP address of the Oracle Database Server was wrong.. That was the cause for the issue :  java.sql.SQLException: Io exception: The Network Adapter could not establish the connection.

Changed the IP address in the oracle connection string and fixed the problem..

I m sharing this with you because, It was an enjoyable analysis, and the cause was interesting..
One more time , it showed the importance of the control.. 

At the end of the day, the key concept of this blog post becomes -> "while investigating such abnormal issues, do not trust the information based on someone else's analysis passed to you! Do your own analysis , check the problem as a whole, prove your discovery and then offer your solution.." 

No comments :

Post a Comment

If you will ask a question, please don't comment here..

For your questions, please create an issue into my forum.

Forum Link: http://ermanarslan.blogspot.com.tr/p/forum.html

Register and create an issue in the related category.
I will support you from there.