Creating an ODBC data source
Make sure you have Oracle ODBC software installed on your PC
before you start, and a suitable tnsnames.ora file in the oracle/network/admin folder to identify local database hosts.
You can pick up
the tnsnames.ora file (if you find you need it- for example if you get
unrecognised service name) from a previous installation
or from Maggie Shapland and paste it into the
newly created oracle/ora90/network/admin/ folder making sure
the old tnsnames.ora that was created by default if you did not exit,
is renamed first.
For each
connection, the entry
looks like (where datasource alias, machine_address, and database_name must
be specified):
datasource alias=
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = machine_address)(PORT =1521))
)
(CONNECT_DATA =
(sid = database_name)
)
)
eg
hprod.bris.ac.uk =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS =
(COMMUNITY = tcp.bris.ac.uk)
(PROTOCOL = TCP)
(Host = sunshine.bris.ac.uk)
(Port = 1521)
)
)
(CONNECT_DATA = (SID = hprod)
)
)
Testing the connection
select the DOS command prompt from Accessories
Type tnsping hprod
(one of the Bristol databases, otherwise type the name of one you want
to test). It should identify the connection and confirm OK
Creating a Data Source
You need to create a data source to be able to use Access as a front end
to Oracle
- Select Microsoft ODBC administrator from Oracle/Network
Adminstration
- Data source types
- Select the user DSN tab if the data source will only be used
from
your PC for the logged on username (Typically, entries in this tab are
added by
applications that are installed
locally and that use a data source, such as Microsoft Office) else
select the System DSN tab.
- The System DSN tab allows you to configure a specific
data source to a client-server database. Using the System DSN tab to
configure a
connection will
write an entry for that connection in the registry in
HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.INI\ODBC Data Sources.
The advantage of this is faster access, since it is in the registry.
The disadvantage is that it will have to be created on each local
machine.
- The File DSN tab does the
same thing as the System DSN tab, but the
File DSN tab will create a file stored on the local server with the
extension .dsn on the local drive in the folder at
C:\Program Files\Common Files\ODBC\Data Sources.
The advantage of this approach is that the file can be easily copied
to other machines.
- Press Add
- You will be asked which driver to use. Choose Oracle in OraHome90
NOT Microsoft ODBC for Oracle since this is the driver that you
have just installed
and will not cause problems such as described in
ODBC Problems
- Choose a data source name- can be the same as the data source service
that you specified above eg xxx or perhaps the username to be used
- Choose a description eg xxx
- Give a data source service name. This must relate to the definition in
the tnsnames.ora
file eg xxx
- Give the default username for that datasource
- Click OK
- You can now test the data source by using ODBC test from
Oracle/Network
Adminstration
- Press Connect
- Choose a data source from the Machine Data Source tab
- Give the passwd for the given service name and username
- Type some SQL eg select table_name from user_tables
- Press the Execute button and hopefully some data will appear
- If something goes wrong, test the service name by typing tnsping xxx
on the Command Prompt found in Program /Accessories on the
Start menu to check the database is up
- The Connection Pooling tab allows you to enable and configure
connection pooling for a specified driver. Connection pooling uses a
connection to a data source from a pool of connections, so that a
connection does not have to be reestablished each time you access the
data source. Unless you are having trouble establishing or
maintaining a connection, you probably will not use this tab. Connection
pooling timeout is set to 120 second by default.
Accessing Oracle Data
To access Oracle data, create an external
link.
Attaching data means that you are using an external link to the
data at its source. Creating external links to Oracle tables
keeps the Access view up-to-date, avoids duplication of data,
and does not require extra storage space within the Access database.
Attached tables are slower to access than locally stored tables,
and their design can not be changed.
- From the File menu choose Attach.
- Select an ODBC data source by selectin Files of type ODBC databases()
- Select a SQL Data Source that you have already defined.
- Logon to ORACLE by giving an ORACLE username and password.
Note that this is not your host machine username and password.
- Accessible tables are then listed. Highlight the tables
that you want to attach. They are
prefixed by the username that they belong to since you may have
access to other peoples tables. If you want to save the ORACLE
username and password locally so that you will not be asked for
it when you next access the attached tables, click on the 'Save
ID and password locally' box.
Identifying an existing connection definition
If there is already a Microsoft Access database with links to an Oracle database, but the data source has not been defined,
up, there will be a suitable warning message telling you that the ODBC connection has failed when you try to look at the data.
Look at the design of one of the linked tables (you must select the design icon and then look at the properties of the table,
rather than looking at the properties of the table from the main database window). Linked tables are recognisable from the icon
associated with them- Oracle tables have a globe icon.
You will be warned that it is a linked table and that you can not change the structure.
Example properties of linked tables
- Access 2
ODBC;DSN=LAW;DBQ=T:sun:hprod;UID=LAW_USERNAME;TABLE=LAW_USERNAME.PERSON_UNITS
- Access 97
ODBC;DSN=LAW;DBQ=HPROD;ASY=ON;;TABLE=LAW_USERNAME.PERSON_UNITS
- Access 2000 and XP
ODBC;DSN=LAW;DBQ=HPROD;DBA=W;APA=T;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;FRL=F;MTS=F;CSR=F;PFC=10;TLO=0;
;TABLE=LAW_USERNAME.PERSON_UNITS
This shows that ODBC was used to look at the data belonging to the law_username username using database alias hprod
(the name before the description in the tnsnames file which accesses hprod database on the sunshine machine), the data
source was called law,
the name of the table/view was person_units,
and username law_user.
This indicates that to be able to use the Access database to look at the data (and update it if the appropriate permissions have
been given by Oracle), that one needs to set up a datasource called law, use
the identified username and database, and that the database/service has been correctly defined in the tnsnames file.
What to do if the data source no longer works
Use tnsping hprod (or whatever the database connection is called), as described above and check the details match the tnsnames
file.
tnsping uses the Oracle named server to find the connection details, whereas Microsoft Access tends to use tnsnames.ora, so the
details should be consistent. Database administrators may have a habit of moving databases to new machines so do check