Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I setup Oracle ODBC drivers on RHEL 6/Linux

I need to setup Oracle ODBC drivers on RHEL 6 to connect to an Oracle data source residing on a remote Windows machine.

I have taken the following steps:
[1] Installed oracle-instanceclient-basic
[2] Set environment variables: ORACLE_HOME and LD path
[3] Created /etc/oracle/TNSnames.ora and configured but it did not set it correctly

Initially, I got the error, "Connect failed because target or object does not exist"

Then, I set: ORACLE_SID = DB_NAME in the TNSnames.ora file.

But, that did not fix the issue, I got a new error message now: "TNS: net service name is incorrectly specified"

like image 896
Kapil Vyas Avatar asked Dec 17 '12 21:12

Kapil Vyas


People also ask

How do I install Oracle ODBC drivers?

On WindowsDownload the Instant Client ODBC package. Unzip it in the same directory as your Basic or Basic Light package. Execute odbc_install.exe from the Instant Client directory. If Instant Client is 11g or lower, start the command prompt with the Administrator privilege.

How do I know if ODBC driver manager is installed on Linux?

To verify whether unixODBC is installed in the system, you can run the commands which odbcinst and which isql, which should return the path to the corresponding tools, or just run isql, which should print the syntax and available options for the isql utility.

How do I manually install ODBC drivers?

Step-by-step ODBC Data Source Setup in Windows 10In the ODBC Data Source Administrator dialog box, select the System DSN or User DSN tab. Click Add. The Create New Data Source dialog box should appear. Locate the necessary driver in the list and click Finish.


2 Answers

yum install unixODBC
rpm -ivh oracle-instantclient-basic-10.2.0.3-1.i386.rpm #downloaded on http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/linuxsoft.html
unzip instantclient-odbc-linux32-10.2.0.3-20061115.zip #downloaded on http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/linuxsoft.html
cp ./instantclient_10_2/libsqora.so.10.1 /usr/lib/oracle/10.2.0.3/client/lib/
export ORACLE_HOME=/usr/lib/oracle/10.2.0.3/client
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib

Also you need to set $TWO_TASK (default location where Oracle is looking to pickup the server) to point to where the Oracle server is running on Windows - - don't forget to add the listener at the end after the port number:

export TWO_TASK=//213.123.23.19:1521/listener

To chech for the name of listener, type the following commands on the windows prompt that is running the Oracle server:

lsnrctl
status

It will enlist listeners and their state (READY or UNKNOWN). Connect to the listener that is in the ready state: Instance "zelistener", status READY

mkdir /etc/oracle

vi /etc/oracle/tnsnames.ora

MY_SID =
 ( DESCRIPTION =
  (ADDRESS_LIST =
  (ADDRESS =
  (PROTOCOL = TCP)
  (Host = 127.0.0.1)
  (Port = 1521)
  )
 )
 (CONNECT_DATA = (SID = MY_SID)
 )
)

export TNS_ADMIN=/etc/oracle

vi /etc/odbcinst.ini

[OracleODBC-10g]
Description = Oracle ODBC driver for Oracle 10g
Driver = /usr/lib/oracle/10.2.0.3/client/lib/libsqora.so.10.1
FileUsage = 1
Driver Logging = 7

vi /etc/odbc.ini

[simple]
Driver = OracleODBC-10g
DSN = OracleODBC-10g
ServerName = MY_SID
UserID = USER
Password = PASSWORD

isql -v simple

+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
like image 166
Kapil Vyas Avatar answered Oct 31 '22 20:10

Kapil Vyas


I think that we should assign the version of unixODBC. if to connect the oracle12c, we should use the unixODBC-2.3.1

like image 45
bear_wang Avatar answered Oct 31 '22 18:10

bear_wang