Connecting to a Database

See Also

Before you can display or edit data on your Web page in Microsoft® Visual InterDev™, you must connect to a database. A data connection provides your Visual InterDev project with access to a particular database. You can then use this data connection to connect to the database and display its data on your Web page.

When you connect to a database, you first create a data source name (DSN) for the database or choose an existing one. Then, you use the DSN to create a data connection and add it to your project.

To create a data source name

  1. Open your Visual InterDev project and select it in the Project Explorer.

  2. From the Project menu, choose Add Data Connection.

    The Select Data Source dialog box appears.

  3. On the File Data Source tab, choose New.

  4. Select the database driver you want and choose Next. The database driver must match the type of database you are connecting to. For example, if your database is a SQL Server database, select the SQL Server driver.

  5. Type the name for the connection file and choose Next.

    The extension .dsn is automatically added to the file name.

  6. Choose Finish.

  7. In the dialog box or boxes that appear, fill in the driver-specific information, such as the name of the database to access or the file to open.

    Note   When you specify a database, use the relative path to the database, not its location on your development computer. For example, if the database is located on a Web server, use the UNC path to the database. This ensures the database will be available from your Web server.

    You are returned to the Select Data Source dialog box, and the file data source name you created is displayed in the list.

For more information on the types of data sources you can create, see Choosing a Data Source Name in the Microsoft® Visual Database Tools documentation.

Tip   You can also use the ODBC Data Source Administrator (located in the ODBC folder of your Control Panel) to create and name data sources. These data sources will appear in the Select Data Source dialog box, and you can use them to create data connections in Microsoft Visual InterDev.

Once you've created a data source name for a database, you can use it to establish a data connection to that database.

To add a data connection to your project

  1. On the File Data Source tab of the Select Data Source dialog box, select the data source name you created and choose OK.

    A dialog box showing parameters for the data connection is displayed. The dialog box you see depends on the type of data source you have selected. For example, if you select a SQL Server data source, you'll see a SQL Server Login dialog box.

  2. Enter the data connection parameters. For example, for a SQL Server database, enter the login ID and password.

    The data connection is displayed under the DataEnvironment folder in your project, underneath the global.asa folder. You can also browse and edit the data from this database in the Data View window.

You are now ready to retrieve and view the data you want from the database. For more information, see Querying the Database.