How to: Connect to the AdventureWorksLT Database using an .MDF File
This topic describes how to connect to an AdventureWorks Light (AdventureWorksLT) sample database for SQL Server 2008 Express by adding the .mdf data file to a Web site or project in Visual Studio. This file-based approach to creating a data connection is simple, and the data file is portable and can be deployed with the Web site or with project files.
Another way to create a connection in Visual Studio is to create a server-based (rather than file-based) connection by using the connection wizard in Visual Studio. This approach requires more steps and does not offer the portability of a file-based approach. However, it provides more control over how you access the data. For more information, see How to: Set Up an AdventureWorksLT Sample Database for ASP.NET Development.
In order to complete this procedure, you will need:
SQL Server 2008 Express installed on your computer. A basic edition of SQL Server 2008 Express is included with Visual Studio. To download a more advanced version that includes tools, services, and full-text search, see Microsoft SQL Server Express 2008 with Advanced Services on the Microsoft download Web site.
A local copy of the .mdf data file for either AdventureWorksLT or AdventureWorksLT2008. To obtain a copy of the .mdf data file, visit Microsoft SQL Server: Database Product Samples on the CodePlex Web site and download the file that is named SQL2008.AdventureWorksLT2008_Only_Database.zip.
An existing ASP.NET Web site, service, or project in Visual Studio.
To add a database file to a Web site or project
Open the project that you want to add the database to.
In Solution Explorer, right-click the App_Data folder, and then click Add Existing Item.
The Add Existing Item dialog box is displayed.
Browse to the folder that contains the .mdf file for the AdventureWorksLT database that you want to use, select the *.mdf file, and then click Add.
This creates a copy of the database and adds it to your Web site or project.