问题
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.
回答1:
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.

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.
回答2:
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>)
)
)
回答3:
In tnsnames.ora, try changing SERVICE_NAME to SID. That worked for me.
回答4:
My Experience 1. TNSNAMES.ORA is as follows. XE = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (HOST = 192.168.2.116) (PORT = 1521) ) ) (CONNECT_DATA = (SERVICE_NAME = XE) ) )
- Set Windows Environment Variables (ControlPanel --> System --> Detail..) 2-1. Add to PATH c:\oraclexe\instantclient_11_2\ --- install directory of instantclient 2-2. Add New Environment Variable TNS_ADMIN c:\oraclexe\instantclient_11_2\ --> install directory NLS_LANG = JAPANESE_JAPAN.JA16SJISTILDE
- Windows command prompt cd c:\Windows\SysWow64 <--I use 32bit ODBC in 64bit Win7 odbcad32.exe Name : ICODBC <-- as you like Service Name : XE User Name: system Press Connection Test Button
来源:https://stackoverflow.com/questions/11873160/connect-to-an-oracle-db-using-odbc