Search
   >> Home >> Resources & support >> FAQs >> Configuring ODBC for Windows

How do I set up an ODBC data source name in Windows?

Title   Setting up an ODBC data source name in Windows
Authors Rebecca Pope and Kerry Kammire, StataCorp
Date February 2014

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.

Windows 8

  1. If you have Windows 8.1, click on the Start button and select Control Panel. Otherwise, search for the "Control Panel" app using the search tool on the side of the start screen.
  2. 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.

  3. In the ODBC Data Source Administrator, click on the Add button.

    ODBC Data Source Administrator

  4. 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.

    ODBC Data Source Administrator - Add

    Click on Finish.

  5. 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.

  6. 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.

    ODBC Data Source Administrator - Add

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.

Vista/Windows 7

  1. Click on the Windows Start menu and then select Control Panel.

  2. 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.

  3. In the ODBC Data Source Administrator, click on the Add button.

    ODBC Data Source Administrator

  4. 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.

    ODBC Data Source Administrator - Add
  5. Click on Finish.

  6. 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.

  7. 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.

    ODBC Data Source Administrator - Add
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.

  1. Make sure you have your DSN configured correctly. Go back into the ODBC Data Source Administrator, and double check your data source settings.

  2. 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/942976
  3. Make 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.

The Stata Blog: Not Elsewhere Classified Find us on Facebook Follow us on Twitter LinkedIn Google+ Watch us on YouTube