Post: http://msdn.microsoft.com/zh-cn/library/aa992075 (loband). aspx
Download
In learning sql2005, you cannot leave the sql2005 sample database. You can download and install the adventureworks database, download and install the northwind database, and download and install the pubs database. The three libraries of adventureworks, northwind and pubs on Microsoft are hard to find and e-mapreduce is easy to use today. Download the SQL 2005 sample library. After decompression, there are two folders: adventureworks and northwind. How to install and use the adventureworks database: There is an adventureworksdb. MSI file under the adventureworks folder. Double-click to install. Then attach the database to SQL 2005. The location of adventureworksdb. DBF is: C: \ Program Files \ Microsoft SQL Server \ mssql.1 \ MSSQL \ data \ adventureworks_data.mdf Install My SQL 2005 on c: \ Program Files \ (that is, the default installation path for installing SQL 2005) In this step, the installation of adventureworks is complete. How to install and use the northwind database and pubs database: The file sql2000sampledb. MSI is located under the northwind folder. Double-click to install. Default installation path: C: \ SQL Server 2000 sample Databases It includes the SQL script files of the northwind database, pubs database, northwind database, and pubs database. You can choose to run the query or additional database. Cngothic adopts the additional method. Attach two databases to SQL. This ends. |
This walkthrough demonstrates how to install SQL Server 2005AdventureworksSample Database, which is required to perform other drills in the reportviewer document.AdventureworksIt is not automatically installed with SQL Server or SQL Server Express, but can be downloaded from the Microsoft website. You can use the instructions provided in this walkthrough to download and installAdventureworksDatabase and configure its connection.
Distributed along with SQL Server 2005AdventureworksVersion andAdventureworksEarlier versions are different. Therefore, even if you have installed an earlier version of adventureworks, you must install the latest version to make the queries in other reportviewer rehearsals run properly.
To learn more aboutAdventureworksFor more information about the sample database, you can search "adventureworks example OLTP Database" in SQL Server 2005 books online ". Most versions of Visual Studio 2008 provide books online. You can also view it in msdn that is located on the http://www.microsoft.com. You can also download adventureworks OLTP database digraphs from the http://www.microsoft.com/downloads ).
Required
You must install an SQL server instance and have relevant permissions on it. If SQL Server 2005 Express is installed, the default Instance name is(Local) \ sqlexpress. If you want to upgrade an MSDE instance to SQL Server 2005 Express, see the SQL Server online series topic "upgrade MSDE to SQL Server Express ".
The following steps describe how to download, save, attach, and configureAdventureworksDatabase.
Download adventureworksdb. MSI
Navigate to the Microsoft website that provides download. Double-click adventureworksdb. MSI.
Click"Run"Complete the installation wizard. Adventureworks_data.mdf and adventureworks_log.ldf will be copied to the SQL server data directory. For SQL Server 2005 Express, the default directory is c: \ Program Files \ Microsoft SQL Server \ mssql.1 \ MSSQL \ data \.
Check the SQL server data directory
Open a Visual Studio 2008 command window. For this reason, go"Start"Click"All Programs","Microsoft Visual Studio 2008","Visual Studio Tools"And"Visual Studio 2008 command prompt".
In the command line, type or copy the following command to open the connection to the local SQL Server express instance:
SQLCMD -S (local)\sqlexpress -E
Press"Enter".
At the sqlcmd prompt, type or copy the following command.
select physical_name from sys.database_files where name = 'master'go
This query will return the location of the master. MDF file to confirm that it will be placedAdventureworksThe SQL Server Data Directory of the database file.
Attach adventureworks to SQL Server
In"Sqlcmd 1>"At the prompt, callSp_attach_dbStored Procedures to appendAdventureworksDatabase. The following code uses the default location of SQL Server 2005 Express. Edit the text as needed to use the data directory confirmed in the preceding steps. In the command window, type the following statement, or copy the statement and paste it in the Command window (the statement cannot contain line breaks ).
exec sp_attach_db @dbname=N'AdventureWorks', @filename1=N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\AdventureWorks_Data.mdf', @filename2=N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\AdventureWorks_log.ldf'
TypeGo.
Press enter. You may see a series of messages about database conversion and upgrade.
Type"Exit"Close the command window.
Verify that adventureworks has been attached
Open Visual Studio 2008. You do not need to open a project.
Slave"View"Select"Server resource manager".
In"Server resource manager"Window, right-click"Data Connection"And then select"Add connection". It will be opened immediately"Add connection"Dialog box.
Confirm"Data Source"Set"Microsoft SQL Server (sqlclient )".
In"Server name"Enter (local) \ sqlexpress in the text box.
In"Log on to the server"Select your authentication method.
In"Select or enter a database name"To expand the database list.
Select "adventureworks" .
Click"Test connection"To verify that the connection to adventureworks is successful.
Note: |
After the connection is established, if you want to query the data source, right-click the data connection icon of adventureworks and select"New query"To call"Query expression"Window. |
Configure adventureworks to use web server controls
Open a Visual Studio 2008 command window to run sqlcmd. You will use sqlcmd to grant access permissions to databases and ASP. NET accounts.
On Windows Server 2003, ASP. NET processes used by web server controls run under nt authority \ Network Service. On other Windows operating systems, this process runs under machinename \ ASPnet.
If SQL Server express 2005 is installed, type or copy the following sqlcmd to grant the service logon permission. Otherwise, you must specify"(Local) \ sqlexpress"SQL Server instance.
The following example applies to Windows Server 2003 and does not contain line breaks.
sqlcmd -E -S (local)\sqlexpress -Q "sp_grantlogin N'NT AUTHORITY\NETWORK SERVICE'"
To grant access to adventureworks for this service, use the following command (cannot contain line breaks ).
sqlcmd -E -S (local)\sqlexpress -d AdventureWorks -Q "sp_grantdbaccess N'NT AUTHORITY\NETWORK SERVICE'"
To add this serviceAdventureworksIn the owner role account, use the following command (cannot contain line breaks ).
sqlcmd -E -S (local)\sqlexpress -d AdventureWorks -Q "sp_addrolemember 'db_owner', N'NT AUTHORITY\NETWORK SERVICE'"
Close the command window.
If the drill can be completed successfully: in local processing mode, use the database data source with the reportviewer Web Server Control to confirm that the configuration is correct.
Subsequent steps