Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect to an Oracle DB using ODBC

Tags:

oracle

odbc

I am developing an application that needs to interract with a "lightly documented" Legacy Oracle Database. To Start that process I want to start creating a view into that Database using ODBC links into an MS Access database so I can figure out the DB structure but I can't figure out how to setup the ODBC connection to the Oracle DB.

I have been able to connect using the Host and Service Name to and view the DB using SQL Developer; but, I can't figure out how to setup ODBC. I am running Windows 7 and have installed Oracle 11g, Oracle Express Edition, the Instant Client and ODBC extensitons; but on the ODBC setup Oracle wants me to pick a TNS Service Name but there is none to pick and there is no place to specify the host. I tried to setup a TNS in tnsnames.ora; but I am not really sure I know the right location for that file.

I really thought this would be the easy part; but, it really hasn't been.

like image 519
markshancock Avatar asked Aug 08 '12 21:08

markshancock


2 Answers

Navigate to the Control Panel > Administrative Tools > Data Sources (ODBC)

Select the System DSN tab and click 'Add'. Next scroll down the lists of drivers until you find Microsoft ODBC for Oracle.

enter image description here

Fill in the required information in the above form and click 'OK'. Now you can add the tables to 'Access' by clicking on the 'External Data' tab then clicking on 'More'. Choose 'ODBC Databases', then 'Import the source data...', next click on the 'Machine Data Source' tab.

like image 79
eabraham Avatar answered Oct 15 '22 08:10

eabraham


The simplest option to generate the tnsnames.ora file is to let Oracle do it. If you launch the Oracle Net Configuration Assistant (Start | Oracle in Oracle Home Name | Configuration and Migration Tools | Net Configuration Assistant), you should be able to choose "Local Net Service Name configuration" which allows you to add (or modify) a TNS alias. That will walk you through gathering the information you'll need to connect.

If you are more comfortable dealing with the text files directly, you can directly edit the tnsnames.ora file in %Oracle Home%\network\ADMIN\tnsnames.ora using this as a template.

<TNS alias> = 
  (DESCRIPTION = 
    (ADDRESS = (PROTOCOL = TCP)(HOST = <hostname or IP>)(PORT = <port>)) 
    (CONNECT_DATA = 
      (SERVER = DEDICATED) 
      (SERVICE_NAME = <database service name>) 
    ) 
  ) 
like image 27
Justin Cave Avatar answered Oct 15 '22 08:10

Justin Cave