|Title||Configuring ODBC for Mac and Linux/Unix|
|Author||Kevin S. Turner, StataCorp|
Configuring ODBC Data Source Names (DSNs) for the Mac OS X and Linux/Unix platforms can be daunting for beginners, so this FAQ provides an overview of the steps you need to take. Most steps are common to both platforms, but some are specific to the database to which you are connecting. Before you start configuring the driver manager, make sure you know which database you are using.
On both Mac and Linux, make sure that your system is running the iODBC driver manager, which stores and manages all the information you need to connect to an ODBC data source. iODBC is an Open Source driver manager maintained by OpenLink Software and released under a dual LGPL/BSD license.
If you are using a Linux/Unix machine and Stata 10 or later, you can also connect to a database with the unixODBC driver manager. In Stata, type set odbcmgr unixodbc to use the unixODBC driver manager. To change back to the default iODBC driver manager, type set odbcmgr iodbc.
At this point, you should have either iODBC or unixODBC installed and running on your system. To configure an ODBC DSN, you will need to specify several parameters, which may vary, depending on the database. Here are a few of the most common parameters (items in bold are usually required):
|Important: Make sure you are using the correct driver for your database. For example, if you have a PostgreSQL database, you will need to use the PostgreSQL ODBC driver, or you will not be able to access the database. Drivers for most of the popular databases, such as Oracle and MySQL, may be available when you install the iODBC driver manager, or you can download the appropriate driver from your database vendor’s website.|
You can configure the ODBC data source either by using the iODBC Administrator utility or by modifying the ODBC configuration files manually.
[ODBC Data Sources] Bug = PostgreSQL [Bug] Debug = 1 CommLog = 1 ReadOnly = no Driver = /usr/local/lib/psqlodbc.so Servername = 64.xxx.xxx.xx FetchBufferSize = 99 Username = kevin Password = passwordforkevin Port = 5432 Database = bugdb [Default] Driver = /home/kst/tmp/libiodbc-3.0.5/odbcsdk/lib/oplodbc.so.1The Driver, Servername, and Username parameters are common to all database types on both the Mac and Linux/Unix platforms. The names and required information for the other parameters may differ, depending on the type of database. See your database’s documentation for information about specific parameters.
Usually, iODBC ships with a small test application you can use to test the connection parameters of any DSN you define. Alternatively, you can start Stata and type odbc list to bring up a list of available DSNs. If you find any errors, you will need to change a connection parameter in the DSN before you try to connect again. I usually have to test a DSN two or three times before I get all the parameters right.