Title | Setting up an ODBC Data Source Name in Stata 15 or earlier in Windows | |
Authors | Rebecca Pope and Kerry Kammire, StataCorp |
Stata's odbc command allows you to load, write, and view data from Open DataBase Connectivity (ODBC) sources. Before you start using the odbc command in Stata, you must first set up a data source name (DSN) in the ODBC Data Source Administrator. Setting up a DSN differs slightly depending on your version of Windows: Windows 8 or Vista or Windows 7.
In the Control Panel, select System and Security and then select Administrative Tools. Under Administrative Tools, double-click on Data Sources (ODBC) to open the ODBC Data Source Administrator.
In the ODBC Data Source Administrator, click on the Add button.
Select the appropriate driver from the list. The driver that you need is determined by the data source you are trying to connect to. For example, choose Microsoft Access Driver (*.mdb) to read from a MS Access database.
Click on Finish.
Assign a name and select the appropriate source. The DSN is completely up to you. You will see a list of available databases or, if you are using Excel, available files. Select the ones you want to associate with the DSN you just created.
The appearance of this dialog box and the number of prompts required to complete this step will vary depending on the ODBC driver you are using.
Once you have finished configuring your data source, you should see your new DSN in the list shown in the ODBC Data Source Administrator User DSN tab.
You are now ready to begin using the odbc command. If you encountered any problems during the setup process, there are some troubleshooting tips below.
Click on the Windows Start menu and then select Control Panel.
If you are using Vista, select System and Security in the Control Panel. Otherwise, in Windows 7, select System and Maintenance in the Control Panel. Next select Administrative Tools. Under Administrative Tools, double-click on Data Sources (ODBC) to open the ODBC Data Source Administrator.
In the ODBC Data Source Administrator, click on the Add button.
Select the appropriate driver from the list. The driver that you need is determined by the data source you are trying to connect to. For example, choose Microsoft Access Driver (*.mdb) to read from a MS Access database.
Click on Finish.
Assign a name and select the appropriate source. The DSN is completely up to you. You will see a list of available databases or, if you are using Excel, available files. Select the ones you want to associate with the DSN you just created.
The appearance of this dialog box and the number of prompts required to complete this step will vary depending on the ODBC driver you are using.
Once you have finished configuring your data source, you should see your new DSN in the list shown in the ODBC Data Source Administrator User DSN tab.
You are now ready to begin using the odbc command.
If you encountered any problems during the setup process, there are some
troubleshooting tips below.
Using the odbc command
Now that you have set up your DSN, open Stata, and type odbc list in the Stata Command window. You should see your new data source displayed in the Results window.
. odbc list Data Source Name Driver ------------------------------------------------------------------------------- test Microsoft Access Driver (*.mdb) -------------------------------------------------------------------------------
To find out how to do useful things with your data source, such as read
from it and write to it, see
[D] odbc.
Troubleshooting
If you encounter the error r(682) "Data source name not found and no default driver specified", follow these steps.
Make sure you have your DSN configured correctly. Go back into the ODBC Data Source Administrator, and double check your data source settings.
Make sure you are using the correct version of the ODBC Data Source Administrator. 64-bit Windows ships with two different ODBC Data Source Administrators, 64-bit and 32-bit. If you are using 32-bit Stata, use the 32-bit ODBC Data Source Administrator. If you are using 64-bit Stata, use the 64-bit ODBC Data Source Administrator. Type about in the Stata Command window to see whether you are using 64-bit or 32-bit Stata. The first line of the output provides this information.
. about Stata/MP 13.1 for Windows (64-bit x86-64) Revision 15 Jan 2014 Copyright 1985-2013 StataCorp LP ...
Microsoft provides additional information and support for the Windows ODBC Data Source Administrator:
http://support.microsoft.com/kb/942976Make sure you are using the correct driver for the DSN. If you are using 64-bit Stata, you will need a 64-bit driver. If you are using 32-bit Stata, you will need a 32-bit driver. You should be able to download the appropriate 64-bit or 32-bit database driver from your data source's database vendor. You will have to follow the driver installation instructions for it to show up in the ODBC Data Source Administrator.