Adding a Data Connection to a Database Project

See Also

When you create a new database project, you choose a data source name (DSN) that specifies the location and type (ODBC driver) of the database you want to access. After you have selected a DSN, Microsoft® Visual Database Tools adds a data connection to your project that stores the connection information from the DSN used to connect to a database server. For details about choosing a DSN, see Choosing a Data Source Name.

Note   In Microsoft® Visual Basic® you can either add a data connection to the data environment, or make a data connection directly from the Data View window. In Visual Basic, all data connections are made through OLE DB, although you can still use ODBC data source names (DSNs) to define your connections.

A database project can contain multiple data connections. You must add one data connection when you create a database project (except in Microsoft® Visual InterDev™ and Visual J++™, for which you can add the data connection later). You can also add more data connections later if your project requires you to access multiple databases.

Note   When specifying a database to use in a project, it is important to specify a location that will work not just in the development environment you are using, but in your final project. If your project involves a database that is accessed from a Web server, use a Universal Naming Code (UNC) to be sure that the database location you specify is accessible from the Web server.

To add a data connection to a database project

  1. In the Project Explorer, right-click the database project you want to add a data connection to, and then select Add Data Connection.

    Note   In Microsoft® Visual C++®, right-click the database project in FileView.

  2. In the Select Data Source dialog box, choose the File Data Source tab to select or create a file DSN, or the Machine Data Source tab to select or create a DSN stored in the Windows® Registry of your computer. For more information, see Choosing a Data Source Name.

  3. Choose an existing DSN or create a new DSN for the database server you want to connect to.

    For more information about creating a file DSN, see Creating a File DSN.

    For more information about creating a machine DSN, see Creating a Machine DSN.

After you have successfully added a data connection, the name of the new data connection is displayed as a node under the project name in the Project Explorer (FileView in Microsoft Visual C++).