Friday, January 28, 2011

SQL Developer connection to Oracle db via LDAP

How can we create a SQL Developer connection to Oracle db via LDAP ?

Let me first cover how to create a SQL Developer connection to Oracle db via LDAP.
We need to have ldap.ora and sqlnet.ora files for this connection to work.

sqlnet.ora file

Note : Please take a backup of the existing sqlnet.ora file, we'll need it to connect to other db which do not use LDAP.

Set the following parameters
NAMES.DIRECTORY_PATH= (LDAP,ONAMES,TNSNAMES)
NAMES.DEFAULT_DOMAIN = xxx.xxx.com
NAMES.PREFERRED_SERVERS = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = hostname1)(PORT = 1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = hostname2)(PORT = 1521)) (CONNECT_TIMEOUT = 0) )
NAMES.REQUEST_RETRIES=2
NAMES.INITIAL_RETRY_TIMEOUT=10

For Preferred servers, hostname2 is optional. Also make sure that the port numbers are correct.
You can also add the following connection timeout parameter so that you don't have to reconnect every time, especially if you are connecting from VPN.

SQLNET.INBOUND_CONNECT_TIMEOUT=600

ldap.ora file
Set the following parameters, the values show are just an example.

DEFAULT_ADMIN_CONTEXT = “ou=oracledatabases,dc=mycompany,dc=com”
DIRECTORY_SERVERS = (ldap_server1.mycompany.com:389:636, ldap_server2.mycompany.com:389:636, ...)
DIRECTORY_SERVER_TYPE = OID

Place these 2 files in your $ORACLE_HOME/network/admin folder.

SQL Developer
Open a new SQL Developer connection and do the following
Select Connection Type = LDAP
Select LDAP Server from the drop down list
Select the appropriate context -
example - cn=OracleContext,ou=oracledatabases,dc=mycompany,dc=com
DBService - Click on Load Button then select the dbservice.

Now, Click on Test then Save and Connect.

Here you are! Successfully connected.