Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
http://www.jrbarnett.freeserve.co.uk/
An Introduction to ODBC.
ODBC stands for Open DataBase Connectivity. It is a client side cross platform data
communication standard developed by Microsoft and is used predominantly on the Windows
platform, although I am aware of implementations for some Unix platforms as well. I will
concentrate on the Windows systems here as this is by far the most common.
From the point of view of the system user/administrator, ODBC has three aspects:
• The ODBC driver
• The ODBC Administrator
• The ODBC Data Source (DSN)
Some common drivers such as text files are supplied as part of the operating system. If the driver is
required as part of a larger application, it will typically be installed as part of an application's client
together with related utilities.
2
Typically for a client/server RDBMS the details would include the server or domain it is hosted on,
network protocol and the username and password to connect. If file based the details would include
a path to the file either as a drive mapping or a UNC name and username/password.
If you run the ODBC Administrator, you will find that there are three types of data source, each
with their own tab:
Entries in the User DSN tab are specific to your user profile. If you are on a network with roaming
profiles enabled they will follow you around as you login to various computers. However, the full
driver must be installed on each workstation for it to work.
Entries in the System DSN tab are available to anybody who logs into that computer (provided that
access rights permit).
Entries in the File DSN tab can be shared and easily copied between systems giving an easy way to
duplicate a connection, provided that the full drivers have been installed on each computer.
Entries of different types can have the same name (although you can't have two of the same type
with the same name). However, connection from an application to a data source it is done by name
rather than name and type. If there are multiple connections with the same name, the User data
source takes priority, then the System source, with the File coming last.
Connection from within a program either has details stored in a ConnectString with your
application code (such as MS Access), which will typically take the form of
"DSN=MyDSN;UID=Alf;PWD=passw0rd;" or you will be requested for a username, data source
and password when trying to connect.
The above example will connect to the data source called MyDSN as user Alf with password
passw0rd. Usernames and passwords can of course be omitted if the data source has them stored in
its preferences, or you wish to override the stored names.
If you are developing a server side application that could be used as a data provider, you would
need to write drivers that conform to the ODBC standard, available from the Microsoft Data web
site shown above.
3
Questions and Answers
Q: What are the differences between the 16 bit and 32 bit ODBC drivers?
A: Apart from the fact that 16 bit drivers were written for use under Windows 3.1, and 32 bit ones
for every version of Windows from 95 onwards, not a lot. Typically they will include the same
facilities and the 32 bit version is obviously preferable on newer machines, being a lot faster in
many cases.
However, 16 bit applications cannot use 32 bit drivers even if running on a 32 bit operating system,
and this is why I still included details of the 16 bit administration tool.
4
File DSN's are stored (on my system running Windows 2000 Pro SP3) in C:\Program
Files\Common Files\ODBC\Data Sources. This can be changed through Tweak UI if you really
want to, but don't unless necessary.
For 16 bit ODBC drivers and data sources, details of drivers are stored in ODBCINST.INI and
details of DSN's are stored in ODBC.INI, both of which will be in your Windows directory.
Please always use the ODBC Administrator to edit and configure your data sources. Don't edit the
registry or INI files unless you are absolutely sure you know what you are doing and have a good
known working backup.
Q: What is an RDBMS?
A: Relational DataBase Management System. It encompasses anything that follows the late Dr.
Edgar (Ted) Codd's 12 Laws of database design, developed back in the 1970's. Many client/server
RDBMS systems are available, including Sybase, SQL Server/MSDE, Oracle, DB2, Ingres,
Informix, MySQL and PostgreSQL.
Desktop database engines (those that don't use a separate backend server) include Jet (used by MS
Access and Visual Basic), Paradox and dBase.
This section contains solutions to real life ODBC problems that the author has fixed during his
career.
Q: My data source shows up in the User DSN tab and is configured correctly. I can connect to it
through applications I run, but my ASP/PHP web page (or other server side application) can't
connect, giving errors. Help!
A: Remember what I wrote about User DSN's being part of your profile. Server side applications
such as IIS and Apache typically logon to the host server as a non interactive system user and as
such won't have access to your profile, which user DSN's are stored in. Recreate the DSN as a
System one and you will be fine (You will need Administrative level access to the server to create
or edit a System DSN).
5
Q: A colleague and I logon to the same PC at different times and get different results when we
view the contents of a data source. The data hasn’t changed between the times we logon and off.
Why?
A: You have either a system data source set which is being overridden by a User source, with
slightly different sources, or you each have a User source that have slightly different settings to
each other.