(Originally posted at May 19th, 2008 by Robje)
In this post, I describe how you can make an Oracle database link to an MS Access database. When done, you can query from an oracle database onto an Access database. But with some little changes, you can do the same trick to a SQL Server database or even a database type you like (to which you can connect by ODBC).
Important: The init-parameter GLOBAL_NAMES should have value FALSE. Check this parameter first before continuing the procedure.
In this example, I uses TESTDB as database name, replace this with your database/name/user id. If I mention %oracle_home%, I mean the Oracle Home directory. This example is worked out on an Oracle 220.127.116.11 installation, but I suppose it will work on higher Oracle versions too.
1. Create a new ODBC link
- On the Oracle server start the ODBC Data Source Administrator. This can be done by using the run command: go to start/run and type odbcad32 and press enter.
- In the ODBC Data Source Administrator window go to the System DSN tab and click on Add...
- Choose in the Create New Data Source window the Microsoft Access Driver (*.mdb) and click on Finish.
- In the ODBC Microsoft Access Setup window enter the data source name (e.g. TESTDB), the description (e.g. Test database) and select the Access database
- If the Access database is on the same machine as Oracle is running, you can ignore step 1.5 and step 2!
- If the Access database is on another machine in the network, you should use UNC-path notation. In the Map Network Drive window, leave the drive-letter on (none) and select via the UNC-path the Access database. Finish the creation of the ODBC Link and close all the ODBC windows.
2. Create Network ID
In order to perform a good connection to the Access database on another machine, you need to follow the following steps:
- Create on the network an user id (e.g. TestDbAdmin) and give this UID read rights on the location of the Access files. NOTE: use the appropriate rights, this depends on the actions you want to take on the Access database.
- Place this user, TestDbAdmin, in the ORA_DBA group on the Oracle server.
3. Create the Oracle TestDb listener
In these steps, some Oracle files will be created and/or modified. A new listener will be created, which will take care of the connection
1. Open the file inithsodbc.ora (%oracle_home%/hs/admin) and save this as initTESTDB.ora. Edit the content so it looks like:
# This is a sample agent init file that contains the HS parameters that
# are needed for an ODBC Agent.
# HS init parameters
HS_FDS_CONNECT_INFO = HORSODBC
HS_FDS_TRACE_LEVEL = OFF
# Environment variables required for the non-Oracle system
2. Open the file listener.ora (%oracle_home%/network/admin) and add the following text, save and close the file:
(ORACLE_HOME = C:\oracle\ora81)
3. Open the file tnsnames.ora (%oracle_home%/network/admin) and add the following text, save and close the file:
(ADDRESS = (PROTOCOL = tcp)(HOST = localhost)(PORT = 1522))
(SID = TESTDB)
(HS = OK)
4. Check the file sqlnet.ora (%oracle_home%/network/admin) if the following setting is correct (correct if it differs):
5. Start the new TESTDB listener with the following command (on the command line tool):
NOTE: DON'T USE A RDP (REMOTE DESKTOP) CONNECTION! Because of windows credential error. Apply this directly on the Oracle machine or via e.g. VNC Viewer connection.
Orahome\bin\lsnrctl start listenerTestDb
Starting the new listener can produce an error message, because the services uses the default logon settings (system account).
6. Configure the ListenerTestDb:
- Open the properties panel of this service (can be found in the windows services list at the administrative tools)
- Stop the service (if it is running) and edit the log on credentials to the user account earlier made (e.g. TestDbAdmin)
- (Re)start the service.
7. Test the listener with the following statement:
If the test succeeded, the database link in Oracle can be made.
4. Create Oracle Database Link to TestDb
1. Create database link to TESTDB (note: credentials SYSTEM/MANGER can be changed to your configuration):
CREATE PUBLIC DATABASE LINK “TESTDB”
CONNECT TO "SYSTEM"
IDENTIFIED BY "MANAGER"
2. Test the link with a count(*) query to a table on the TESTDB database.
If you got a number of rows back, you're done!