Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Beginning ASP.NET 2.0 With CSharp (2006) [eng]

.pdf
Скачиваний:
84
Добавлен:
16.08.2013
Размер:
20.33 Mб
Скачать

Appendix B

Figure B-18

6.Click Finish. Close the MMC Console. A save is optional, and you can supply a name if you so desire.

Wrox United Installation

Go to www.wrox.com and search for the dedicated page for Beginning ASP.NET 2.0 with C++ (ISBN: 0470042583). When you are there, you can download the Wrox United application, which comes as a single downloadable zip file containing the database and application. Download the zip file and save it to the C:\Websites\WroxUnited folder you created earlier. Next, unzip this file to C:\Websites\.

It will automatically put files in the WroxUnited folder for you, so be careful not to extract it to

C:\Websites\WroxUnited, because you could end up with C:\Websites\WroxUnited\WroxUnited. In Windows Explorer, make sure that inside your C:\WebSites\WroxUnited is an App_Data folder and that it has four files.

In particular, make sure that the following file names are present:

WroxUnited.mdf

ASPNETDB.mdf

WroxUnited_log.ldf

ASPNETDB_log.ldf

If not, go back and try downloading the zip file again.

658

Setup

Network Service Enabling

The last step before you can test the application is that you might need to add Write permissions to the Network Service account. This will allow ASP.NET to use the database and to read data from it and write data to it, as is routinely required throughout the course of this book. You can skip this step if you are using Windows Server 2003, because the Network Service account has these permissions already enabled by default. If not, then you will almost certainly have to enable Write permissions first. Here’s how:

1.Go to Windows Explorer and select the C:\WebSites\WroxUnited\App_Data folder. Rightclick it and select Sharing and Security. Select the Security tab, shown in Figure B-19.

Figure B-19

If you can’t see the Security tab, this is because you have Simple File Sharing switched on. To disable it, select Tools Folder Options from Windows Explorer, and select the View tab. Scroll to the bottom and uncheck the Use Simple File Sharing option (see Figure B-20). If you can’t see the Simple File Sharing option, this is because you have Windows XP Home Edition installed and it has Simple File Sharing switched on permanently, and you cannot change it. Instead, you will have to take another course as outlined in the next section.

659

Appendix B

Figure B-20

2.Click the Add button in the Wrox United Properties dialog box and in the Select Users or Groups dialog box that appears. Type NETWORK SERVICE into the text box and click Check Names. NETWORK SERVICE will become underlined, as shown in Figure B-21.

Figure B-21

If the machine is joined to a domain, you must select the Locations button first and pick the current machine, rather than the domain. That’s because NETWORK SERVICE is an account on your machine. By default, the dialog will attempt to add the domain name, rather than the machine name.

660

Setup

3.Click OK. You are returned to the Wrox United Properties dialog box. This time, select the new NETWORK SERVICE option. Scroll down and check the box next to Write (see Figure B-22). Click Apply, and then click OK.

Figure B-22

This will enable your account to access the database.

Windows XP Home Edition Users Only

If, when you come to browse for a Security tab in Windows Explorer, you can’t find one, this is because you have Windows XP Home Edition installed and you have a slightly more complex route to enable the correct permissions. Apparently, Windows XP Home Edition users just aren’t allowed to have the same kind of power as their XP Professional counterparts. To get around this, restart your computer in Safe Mode.

To do this, restart your machine, and before the Windows XP logo appears, hold down the F8 key and select Safe Mode. Let XP continue and then log in as Administrator. You’ll receive a warning about running in Safe Mode, but click Yes anyway. Locate the C:\WebSites\WroxUnited folder in Windows Explorer and right-click the App_Data folder. Select Properties and select the Security tab that has now appeared. Now go back to step 1 in the previous section and follow the instructions from there on. At the end, though, shut down and restart your machine in normal mode before you continue to the next step.

Checking the Installation with VWD and the ASP.NET Development Server

After you have successfully downloaded the Wrox United zip file, unzipped it, and enabled the Network Service, you are ready to check your installation. Follow these steps:

661

Appendix B

1.Select the Start menu and navigate to All Programs. Select the Visual Web Developer 2005 Express Edition Icon at the bottom of the menu. VWD will open.

2.Select File Open Web Site, and browse to C:\Websites\WroxUnited and click Open. When the web site has loaded into Solution Explorer, double-click default.aspx to open the file. Press the F5 key to run the page and observe it in a browser. You should see what appears in Figure B-23 in your browser.

Figure B-23

Checking the Installation with IIS

Follow this step only if you have installed IIS and intend to use it as your main web server. To open WroxUnited with IIS, start Internet Explorer and type http://localhost/WroxUnited into the Address line. The web site should start and display what’s shown in Figure B-24.

Please note that while Figure B-22 is seemingly identical to Figure B-21, the Address line reveals a small difference. If you are running your site on ASP.NET Development Server (the free web server with VWD), you will get the following line (potentially with a different number):

http://localhost:1231/WroxUnited

This indicates that the web server is running on port 1231. The ASP.NET Development Server will arbitrarily assign a port number in the URL. If you are running the web site on IIS, then you see the following line:

http://localhost/WroxUnited

662

Setup

Figure B-24

IIS by default runs on port 80, and this doesn’t need to be specified in the URL.

Occasionally, if port 80 is taken by another process, IIS will default to http://localhost:8080, or you might have to specify it yourself if you get an error message saying Unexpected error 0x8ffe2740 occurred.

This means that another application is using port 80. To alter this, you need to start the IIS manager from Administrative Tools in the Control Panel, right-click the Default Web site in the left panel, and select Properties. From the Web Site tab, change the number there from 80 to 8080, or if 8080 is taken then 8081, or the first one free above that number.

Troubleshooting

By and large, installation with SQL Express and the ASP.NET development is straightforward. However, if you are trying to use SQL Server 2005 rather than SQL Express, you should run through the following extra steps:

1.Add [machine\ASPNET] and [NT AUTHORITY\NETWORK SERVICE] as logins, substituting machine with your machine name.

2.Attach the database (wroxunited.mdf), making ASPNET the db_owner.

3.Add [machine\ASPNET] and [NT AUTHORITY\NETWORK SERVICE] as database users.

4.Change the connection strings in web.config. That should be all for the WroxUnited database. Then there’s the providers, which can be added to either the WroxUnited database or to a separate one.

663

Appendix B

5.Run aspnet_regsql (in the framework directory), to add user/roles/etc tables/procs to the appropriate database.

6.Add provider sections in web.config, for <membership>, <roles>, and <profile>, setting the default provider for each to the new provider added. These providers should point at the ConnectionString for the database (which will be either WroxUnited or a new connection string if you’re using another database).

Note that if you are using a different version of SQL Server than 2005, it isn’t possible to just attach the database to the different version. If you are using the full version of 2005 and you encounter the following problem:

Server Error in ‘/WroxUnited’ Application.

Failed to generate a user instance of SQL Server due to a failure in copying database files. The connection will be closed.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Failed to generate a user instance of SQL Server due to a failure in copying database files. The connection will be closed.

you will need to do the following:

1.Reboot windows.

2.Log in as Administrator (if you aren’t running with Admin privileges).

3.Delete the C:\Documents and Settings\username\Local Settings\Application Data\ Microsoft\Microsoft SQL Server Data\SQLEXPRESS directory.

You might need to logout and log back in as a “normal” user if you normally run with non-admin privileges.

If this doesn’t work, try the following solution — there is a known problem with remote logging on and SQL Express, which the following steps should circumvent:

1.Go to the SQL Configuration Manager.

2.Right-click SQL Express and select Properties.

3.From the Logon tab, change the account from Network Service to Local System.

4.Try to run it again.

Apart from that, if you encounter a problem go to http://forums.asp.net or http://p2p.wrox.com and check to see if your problem is addressed there.

664

C

Wrox United

Database Design

Throughout this book, you’ve seen examples based on the fictional Wrox United soccer team web site. The application relies on a SQL Server database, supplied with the code downloads for this book (available at www.wrox.com). This database stores details of the players in the team, fixtures and results, news items, orders from the shop, and so on.

This appendix is not intended to provide a thorough overview of database design principles, and as such, we recommend that you read Wrox’s Beginning Database Design.

The database schema looks like Figure C-1.

Figure C-1

Appendix C

This diagram illustrates the tables that exist within the database, and the relationships between those tables. For example, players score goals, goals are scored at fixtures, match reports are written about specific fixtures, and so on. Many tables relate to other tables in the database, but there are some tables that stand on their own; for example, the News table, which stores news articles. This table doesn’t link to data stored in any other table. Notice also that the Orders, Products, and OrderLines tables are separate from the rest of the database — these tables are used to store data relating to orders from the Wrox United shop.

This appendix walks through the structure of each of the tables in the database and describes the relationships between them.

Players and Matches

The players on the Wrox United team are involved in many fixtures, and several related tables in the database store related data for matches. Take a look at these tables first.

The Players Table

The following shows the structure of the Players table.

Field

Data Type

Allow Nulls

 

 

 

PlayerID (Primary Key)

int

No

FirstName

varchar(25)

No

LastName

varchar(25)

No

Position

varchar(50)

Yes

PictureURL

varchar(255)

Yes

DateJoined

datetime

Yes

DateLeft

datetime

Yes

This table is typical of all database tables in that it has the following:

A primary key field that uniquely identifies each row in the database

Fields designed to store textual data about each player (in varchar fields)

Fields that store date and time information

Flags indicating whether or not different fields require values

In this table, the primary key is the PlayerID field, which stores numeric values (integers) that are unique to each player in the database. This field, along with the FirstName and LastName fields, is marked as not allowing null values. In other words, if you enter a row of data in the table, you must

666

Wrox United Database Design

enter values for each of these fields. However, the PlayerID field will be filled with an auto-generated number for you (due to the way it is configured), so the only data you must enter when you create a new row is the full name of the new player. The remaining information describing the player is optional. You don’t have to specify which position the player occupies, and you don’t have to specify when he or she joined.

Note that a varchar field is a field that stores character data of varying length. The number in brackets is the maximum number of characters that can be stored in that field. If the field contains less than the maximum length, it occupies less space in the database. A char field, by comparison, always takes up the same size in the database, no matter how much of the available space is filled with data.

Figure C-2 shows an example of some data from the Players table.

Figure C-2

This screenshot comes straight from Visual Web Developer. You can right-click any database table in the Database Explorer and select Show Table Data to try this out for yourself.

The Goals Table

The Goals table relates directly to the Players table, because players score goals during a match. The following shows the structure of the Goals table.

667