Wednesday, December 28, 2011

Troubleshooting connectivity issues

Troubleshooting connectivity issues can sometimes be a painful process if we are not aware of how we can get a start up in this area.

Let's take an example to see how we can resolve issues if we come across any.
I was trying to do ldap bind with an existing LDAP server ( Oracle Internet Directory ) on HOST1 ( Windows Server 2008 Enterprise R2).
When I tried doing ldap bind from HOST1 , it worked. But when I tried to do it from some other machine , it gave the connection refused message.


[OIDConnectRegModePage] OID Host Name : HOST1
[OIDConnectRegModePage] OID Port : 3131
[OIDConnectRegModePage] Use SSL Only : true
Setting page validations ..
Verify page validation
Starting validation OIDEXISTS
Validating ..
ERROR - DirContext anonymous bind [ HOST1:3131]
javax.naming.CommunicationException: HOST1:3131 [Root exception is java.net.ConnectException: Connection timed out: connect]
at com.sun.jndi.ldap.Connection.(Connection.java:194)
at com.sun.jndi.ldap.LdapClient.(LdapClient.java:119)
at com.sun.jndi.ldap.LdapClient.getInstance(LdapClient.java:1668)
at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2599)
at com.sun.jndi.ldap.LdapCtx.(LdapCtx.java:290)
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:175)
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:193)
at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:136)
at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:66)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
at javax.naming.InitialContext.init(InitialContext.java:219)
at javax.naming.ldap.InitialLdapContext.(InitialLdapContext.java:133)
at oracle.ldap.util.jndi.ConnectionUtil.getSSLDirCtx(ConnectionUtil.java:313)
at oracle.ias.randomtool.DirectoryUtils.getDirCtx(DirectoryUtils.java:52)
at oracle.ias.randomtool.DirectoryUtils.getDirCtx(DirectoryUtils.java:61)
at oracle.ias.repca.validation.validateimpl.OIDValidation.validate(OIDValidation.java:140)
at oracle.ias.repca.validation.util.ValidationQueue.performValidations(ValidationQueue.java:276)
at oracle.ias.repca.validation.util.ValidationQueue.run(ValidationQueue.java:211)
at java.lang.Thread.run(Thread.java:534)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
at java.net.Socket.connect(Socket.java:452)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(DashoA12275)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.(DashoA12275)
at com.sun.net.ssl.internal.ssl.SSLSocketFactoryImpl.createSocket(DashoA12275)
at oracle.ias.randomtool.InstallSSLSocketFactoryImpl.createSocket(InstallSSLSocketFactoryImpl.java:90)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.sun.jndi.ldap.Connection.createSocket(Connection.java:311)
at com.sun.jndi.ldap.Connection.(Connection.java:181)
... 19 more
ERROR - Closing anonymous DirContext:null
Validation Queue Failed : Unable to locate the specified Directory Server. Please verify that the Directory Server is up and running in the specified Host and Port.



In that case, we need to get to the network layer and see if the port is open or not.
PortQuery is a good tool to troubleshoot connectivity issues. I used the PortQueryUI which is much easier to use.


It showed that the port which I was looking for was not open. So, when I added an exception for the port in Windows firewall using the link here , it worked like a charm



There are other ways by which we can check whether port is open or not.
On Windows 2008 , telnet is not available by default and so , it has to be installed and enabled
After it is enabled , we can do telnet for the host and port from some other machine to see if that port is open or not.

> telnet HOST_NAME PORT_NO

Sunday, December 11, 2011

Hostname changed and tnsping not working for Oracle Database server

Let's assume we have Oracle Database server installed on our machine. For some reasons, we had to change the hostname of the machine on which the Oracle db server is installed.

In that case , the tnsping stops working (host1 has been changed to host2 ).

C:\Documents and Settings\amit.upadhyay>tnsping ams

TNS Ping Utility for 32-bit Windows: Version 11.1.0.6.0 - Production on 11-DEC-2
011 17:28:54

Copyright (c) 1997, 2007, Oracle. All rights reserved.

Used parameter files:
C:\app\amit.upadhyay\product\11.1.0\db_1\network\admin\sqlnet.ora


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = HOST1)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_N
AME = AMS)))
TNS-12545: Connect failed because target host or object does not exist

We come to know that tnsnames.ora has to be changed and we go and change it to host2 but now we get the following error -

Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = HOST2)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_N
AME = AMS)))
TNS-12541: TNS:no listener

This means the listener has not started but when we try to start from services , it shows getting started but it doesn't really start. So, to see what is the actual error , open command prompt and go to the location where LSNRCTL.EXE is present -
C:\app\amit.upadhyay\product\11.1.0\db_1\BIN

Type LSNRCTL.EXE

C:\app\amit.upadhyay\product\11.1.0\db_1\BIN>LSNRCTL.EXE

LSNRCTL for 32-bit Windows: Version 11.1.0.6.0 - Production on 11-DEC-2011 17:53
:58

Copyright (c) 1991, 2007, Oracle. All rights reserved.

Welcome to LSNRCTL, type "help" for information.

LSNRCTL>

Enter Start and we will get some error which will point to the actual issue -

LSNRCTL> start
Starting tnslsnr: please wait...

TNSLSNR for 32-bit Windows: Version 11.1.0.6.0 - Production
System parameter file is C:\app\amit.upadhyay\product\11.1.0\db_1\network\admin
listener.ora
Log messages written to c:\app\amit.upadhyay\diag\tnslsnr\inmuml0087\listener\a
ert\log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC152
ipc)))
Error listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=HOST1)(PORT=1521)))
TNS-12545: Connect failed because target host or object does not exist
TNS-12560: TNS:protocol adapter error
TNS-00515: Connect failed because target host or object does not exist
32-bit Windows Error: 1001: Unknown error

Listener failed to start. See the error message(s) above...


It points to listener.ora and when we go and modify the host in this file ( host1 to host2 ) and then try perform start , the tns listener starts successfully.

LSNRCTL can be used from command prompt to debug any issues related to tns listener not starting.