Поделиться через


How to: Create a Data Connection to the Northwind Database

Many data examples require the availability of the Northwind sample database. This topic provides information on creating data connections to the different versions of the Northwind database.

Creating Data Connections to the Northwind Database

Note

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Visual Studio Settings.

To create a data connection to the Northwind database (SQL Server)

  1. On the View menu, click Server Explorer/Database Explorer.

  2. In Server Explorer/Database Explorer, right-click Data Connections and click Add Connection.

    After you click Add Connection, either the Choose Data Source dialog box or the Add Connection dialog box will appear.

  3. If the Choose Data Source dialog box appears, select Microsoft SQL Server, and then click OK.

    If the Add Connection dialog box appears and the Data source is not Microsoft SQL Server (SqlClient), click Change to open the Change Data Source dialog box, click Microsoft SQL Server, and then click OK.

  4. In the Server name list, click or type the name of the server on which the Northwind database is located.

  5. Depending on the requirements of your version of SQL Server and the Northwind database, either click Use Windows Authentication or click Use SQL Server Authentication and type a user name and password to log on to the computer running SQL Server. For more information, see Add/Modify Connection (Microsoft SQL Server).

  6. Click the Northwind database in the Select or enter a database name list.

  7. Click Test Connection to verify connectivity to the Northwind database.

  8. Click OK.

    A data connection to the Northwind database is added to Server Explorer/Database Explorer.

In addition to connecting to a remote instance of a SQL Server database, you can also connect directly to the actual files that contain the database. This enables you to add the database files directly into a project where they can be deployed as part of the application. The following local database files are currently supported: SQL Server Compact 3.5 database files (.sdf), SQL Server and SQL Server Express database files (.mdf), and Microsoft Access database files (.mdb).

To create a data connection to the Northwind database—SQL Server Compact 3.5 database (.sdf)

  1. On the View menu, click Server Explorer/Database Explorer.

  2. In Server Explorer/Database Explorer, right-click Data Connections and click Add Connection.

    After you click Add Connection, either the Add Connection dialog box or the Choose Data Source dialog box will appear.

  3. If the Choose Data Source dialog box appears, select Microsoft SQL Server Compact 3.5, and then click OK.

  4. If the Add Connection dialog box appears, verify that the Data source is set to Microsoft SQL Server 2005 Compact 3.5. If it is not set to Microsoft SQL Server 2005 Compact 3.5, click Change to open the Change Data Source dialog box, click Microsoft SQL Server Compact 3.5, and then click OK.

  5. Click Browse to locate the .sdf file that contains the Northwind database.

  6. Type a password if it is required by your version of the Northwind database.

  7. Click OK.

    A data connection to the Northwind database is added to Server Explorer/Database Explorer.

To create a data connection to the Northwind database—SQL Server database file (.mdf)

  1. On the View menu, click Server Explorer/Database Explorer.

  2. In Server Explorer/Database Explorer, right-click Data Connections and click Add Connection.

    After you click Add Connection, either the Add Connection dialog box or the Choose Data Source dialog box will appear.

  3. If the Choose Data Source dialog box appears, select Microsoft SQL Server Database File, and then click OK.

  4. If the Add Connection dialog box appears, verify that the Data source is set to Microsoft SQL Server Database File (SqlClient). If it is not set to Microsoft SQL Server Database File (SqlClient), click Change to open the Change Data Source dialog box, click Microsoft SQL Server Database File, and then click OK.

  5. Click Browse to locate the .mdf file that contains the Northwind database.

  6. Depending on the requirements of your version of the Northwind database, either click Use Windows Authentication or click SQL Server Authentication and type a user name and password to log on to the computer running SQL Server. For more information, see Add/Modify Connection (Microsoft SQL Server Database File).

  7. Click OK.

    A data connection to the Northwind database is added to Server Explorer/Database Explorer.

To create a data connection to the Northwind database—Access database file (.mdb)

  1. On the View menu, click Server Explorer/Database Explorer.

  2. In Server Explorer/Database Explorer, right-click Data Connections and click Add Connection.

    After you click Add Connection, either the Add Connection dialog box or the Choose Data Source dialog box will appear.

  3. If the Choose Data Source dialog box appears, select Microsoft Access Database File, and then click OK.

  4. If the Add Connection dialog box appears, verify that the Data source is set to Microsoft Access Database File. If it is not set to Microsoft Access Database File, click Change to open the Change Data Source dialog box, click Microsoft Access Database File, and then click OK.

  5. Click Browse to locate the .mdb file that contains the Northwind database.

  6. Type a user name and password if it is required by your version of the Northwind database. For more information, see Add/Modify Connection (Microsoft Access).

  7. Click OK.

    A data connection to the Northwind database is added to Server Explorer/Database Explorer.

See Also

Tasks

How to: Install Sample Databases

How to: Manage Local Data Files in Your Project

Walkthrough: Creating Stored Procedures for the Northwind Customers Table

Concepts

Local Data Overview

Other Resources

Accessing Data in Visual Studio

Data Walkthroughs