Export (0) Print
Expand All

How to: Install Sample Databases

Many Visual Studio topics and code samples require the ability to connect to a database, such as the Northwind and AdventureWorks sample databases.

This topic provides information about the following:

  • Downloading and installing sample databases.

  • Creating a data connection to a database file (.mdf).

  • Converting the Northwind database file (.mdf) for Visual Studio 2012.

NoteNote

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.

Many data examples require the availability of sample databases that can be downloaded from web sites. The sample databases include the AdventureWorks, Northwind, and Pubs databases.

To install the Northwind and Pubs sample databases for SQL Server

  1. Go to the Northwind and Pubs Sample Databases web site.

  2. Download and run the installer.

  3. If you are using Visual Studio 2012, convert the database file (.mdf) to a SQL Server 2012 database file. See the "To convert the Northwind database file (.mdf) for Visual Studio 2012" procedure later in this topic.

  4. Connect to the database file by using the Server Explorer in Visual Studio. See the "To connect to a database file (.mdf) from the Data Connections node" procedure later in this topic.

To install the AdventureWorks sample databases

To install the Northwind sample database for Microsoft Access

  1. Go to Desktop Northwind 2007 sample database on the Microsoft web site, and then choose the Download button.

  2. In Microsoft Access, save the database file.

The new extension for Access databases is .accdb. See Data Programming with Microsoft Access 2010. To connect to the Northwind database by using Access, see How to: Connect to the Northwind Database.

You can connect to a database file (.mdf) from the Data Connections node in Server Explorer.

NoteNote

In Visual Studio 2012, you can connect to a SQL Server database from either SQL Server Object Explorer or the Data Connections node in Server Explorer. SQL Server Object Explorer provides a view that is like SQL Server Management Studio. To open this explorer from the menu bar, choose View, SQL Server Object Explorer. For more information, see Connected Database Development.

To connect to a database file (.mdf) from the Data Connections node

  1. In Server Explorer, open the shortcut menu for Data Connections and choose Add Connection.

    The Add Connection dialog box appears.

  2. Choose the Change button.

    The Change Data Source dialog box appears.

  3. Select Microsoft SQL Server Database File and choose the OK button.

    The Add Connection dialog box reappears, with Microsoft SQL Server Database File (SqlClient) shown in the Data source text box.

  4. Choose the Browse button and browse to an existing database file (.mdf).

  5. Select either Use Windows Authentication or Use SQL Server Authentication. For more information, see Create New SQL Server Database Dialog Box.

  6. Choose the OK button. The database appears in Server Explorer.

    For more information, see How to: Connect to a File-based Database.

To use the Northwind database file (.mdf) with Visual Studio 2012, you must convert the file to a SQL Server 2012 database file. See How to: Upgrade to LocalDB or Continue with SQL Server Express.

To convert the Northwind database file (.mdf) for Visual Studio 2012

  1. Open Microsoft SQL Server 2008 Management Studio, and then attach and detach the database file (.mdf).

    Note Note

    If you don't have SQL Server 2008 Management Studio, you can download SQL Server 2008 Express with Tools from the Download Center.

  2. Open Visual Studio 2012, and then connect to the database file (.mdf).

    For more information, see Connecting to a Database File earlier in this topic.

You can follow these steps to attach and detach a database file (.mdf) in SQL Server Management Studio.

  1. Open Microsoft SQL Server 2008 Management Studio.

  2. On the shortcut menu for Databases, choose Attach.

    The Attach Databases dialog box appears.

  3. In the Databases to attach section, choose the Add button.

    The Locate Database Files dialog box appears.

  4. Choose the database file (.mdf), and then choose the OK button.

    The mdf and .ldf files appear in the Database details section of the Attach Databases dialog box.

  5. Choose the OK button to attach the database.

  6. In the Databases node, open the shortcut menu for the database file (.mdf), choose Tasks, and then choose the Detach button.

    The Detach Database dialog box appears.

  7. Choose the OK button to detach the database.

Always check for product updates when installing additional software.

Show:
© 2014 Microsoft