How to: Set Up an AdventureWorksLT Sample Database for ASP.NET Development
This topic describes how to connect to an AdventureWorks Light (AdventureWorksLT) sample database using SQL Server 2008 for use with ASP.NET Web sites or projects in Visual Studio. Because the AdventureWorksLT sample databases are used with many code examples and sample applications, it is helpful to have an instance of the sample database set up in your development environment. You can also follow the steps in this topic to set up and access any other SQL Server 2008 database in a Web site or project.
Two versions of the AdventureWorksLT database are included with the AdventureWorks 2008 database samples. AdventureWorksLT 2008 is an updated version of the original AdventureWorks sample database that has a new schema and data types. AdventureWorksLT is the 2005 version of the database with the original schema, updated to run on SQL Server 2008. You can use either version.
This topic describes how to perform the following tasks:
How to download and install the AdventureWorksLT sample database package.
How to add a connection to an AdventureWorksLT database in Visual Studio.
In order to complete the procedures that are described in this topic, you will need:
A local instance of SQL Server 2008 or SQL Server 2008 Express. A basic edition of SQL Server 2008 Express is included with Visual Studio. To download a more advanced version of SQL Server 2008 Express that includes tools, services, and full-text search, see Microsoft SQL Server Express 2008 with Advanced Services on the Microsoft download Web site.
Visual Studio 2008 with Service Pack 1 installed, Visual Web Developer 2010 Express with SP1, or a later version of Visual Studio.
To install the sample database
In a browser, visit the Microsoft SQL Server: Database Product Samples page on the CodePlex Web site.
Click the .msi installer package that you want to download. All packages include the AdventureWorksLT database.
Make sure that you select an installer package that is appropriate for the version of SQL Server 2008 (x86 or x64) you are using.
Save the installation file to your computer.
After the download is completed, double-click the downloaded .msi file to begin the installation process.
For more information about how to install the database, Installing Sample Databases on the CodePlex Web site.
After the installation process for the database has completed, you can add a connection to the database in Visual Studio. You can use this connection with any kind of ASP.NET Web site, service, or project that can use a data connection.
To add a connection to the database
In Visual Studio, in the Tools menu, click Connect to Database.
You do not have to open a Web site or project in order to add a connection.
The Add Connection dialog box is displayed.
In the Server name field, enter the name of the SQL Server 2008 instance to use.
The following example shows a typical way to enter the server name, using the default instance name of a SQL Server 2008 Express installation:
Select the type of authentication that will be used to log on to the SQL instance.
It is recommended that you select the option to use Windows authentication, which is more secure than SQL authentication.
In the Select or enter a database name field, enter or select which version of the AdventureWorksLT database that you want to connect to.
After you have installed the AdventureWorksLT database and added a connection in Visual Studio, you can access the data from an ASP.NET Web site or project. There is not a single way to do this, because the approach that you use to access data depends on the type of Web site or project you create. If you have already created a Web site or project in Visual Studio, you can use the connection to AdventureWorksLT that is described previously with any kind of wizard or data source control to access the data.
In general, you can access the AdventureWorksLT data in Visual Studio using one of the following approaches:
Create a data model for a Dynamic Data Web site. In Visual Studio, you can use the LINQ to SQL Classes template or the ADO.NET Entity Data Model template to create the model. You can then use the existing connection to AdventureWorksLT. For more information, see Walkthrough: Creating a New Dynamic Data Web Site Using Scaffolding.
Add a data source control to an ASP.NET Web page, such as a SqlDataSource, LinqDataSource, or EntityDataSource control. When you add one of these controls to a page, a wizard can help you configure access to the data. In the wizard, select the existing connection to AdventureWorksLT.
Manually create a connection string in the Web.config file. This method enables you to customize a named connection string and access it programmatically.
The following example shows a connection string in a Web.config file that references the AdventureWorkLT2008 sample database that is running on a local SQL Server 2008 Express instance.
<connectionStrings> <add name="AdvWorksLT_ConnectionString" connectionString="data source=.\SQLEXPRESS;Integrated Security=True;Initial Catalog=AdventureWorksLT2008;User Instance=true" providerName="System.Data.SqlClient"/> </connectionStrings>