Tài liệu MASTERING SQL SERVER 2000- P18 pdf

50 341 0
Tài liệu MASTERING SQL SERVER 2000- P18 pdf

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

CHAPTER 23 • THE WEB ASSISTANT WIZARD 870 option seen in Figure 23.11 will instruct the Web Assistant Wizard to help format the Web page. The only real problem with using the Wizard to format the Web page is that it turns out kind of bland, a white background with black text. If you want something a little snazzier than that, you can select the option to use a predefined template. To create this template, you will need to know how to program in HTML code and have created the template beforehand. Once you have a template, you need to only point the Web Assistant Wizard to the right file by selecting the second option. Because HTML coding is out of the scope of this book, you are going to have the Web Assis- tant Wizard format the Web page for you by selecting the first option on the screen. FIGURE 23.11 The Web Assistant Wizard can help you format the Web page. Specifying Titles If you instructed the Web Assistant Wizard to use a template file, you would skip ahead a few pages to limiting the number of rows returned, but because you decided to ask for help, you need to tell the Wizard how you want your page to look. The first question, as seen in Figure 23.12, asks what title you want on your Web page; this will show up in the title bar at the top of the Web browser. The next question asks what title you want to give the table that is used to display the data on the Web page; this shows up just above the table at the top of the page. The final question 2627ch23.qxd 8/22/00 11:18 AM Page 870 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 871 asks what size the title should be just above the table; the default is H3 (heading 3), and the size shown is actual. The checkbox at the bottom of the page will allow you to place a time- and datestamp at the bottom of the Web page so that you will know the last time it was updated. This is especially helpful if you have instructed the Wiz- ard to automatically update your Web page. For the purpose of demonstration, you will change the title of the Web page to Northwind Employees and the title of the table to Employee Listing, then click Next. FIGURE 23.12 The Wizard needs some information to help you format your Web page. Formatting the Table The data from the tables in your database is displayed on the Web page as a table—a table that needs to be formatted. Therefore, the next screen will allow you to change the way the table looks on the Web page. The first choice you see at the top of the screen (as shown in Figure 23.13) asks whether the column names should be displayed at the top of the table. All columns have a name that is assigned when the table is designed; if you want that name to be displayed in the table on the Web page, select the Yes, Display Column Names option. If you do not want these to be displayed, select the No, Display Data Only option. PUBLISHING DATA WITH THE WEB ASSISTANT WIZARD Development with SQL Server PART V 2627ch23.qxd 8/22/00 11:18 AM Page 871 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. CHAPTER 23 • THE WEB ASSISTANT WIZARD 872 The next choice to make on this screen is the style of font that you want to use to display the data in the table. The four choices are listed with an example of what the text will look like in the table. At the bottom of the screen, there is a checkbox that will turn on or off the border lines around the table. If border lines are on, the data in each cell of the table will have a box around it; if border lines are off, there will be no box around the data cells. FIGURE 23.13 The table that is dis- played on the page can be formatted to suit your needs. For this example, you will choose to display column names, leave the font as fixed, and leave the border-lines option checked, and then click Next. Linking to Other Sites Usually, when you open a Web page, you see text that is a different color and under- lined. When you move your mouse over this special text, the cursor changes, and when you click the text, you are transported to a different Web page. This special text is called a hyperlink, and on the screen that you see in Figure 23.14, you can add hyperlinks to your page. If you select the first option on the page—No—you will not add any links to your page. If you want to add a single link to the bottom of your page, enter the address of the page and a label for the page by selecting the Yes, Add One Hyperlink option and filling in the data. For example, if you want to add a hyperlink to your company’s main Web page (called the home page), you could enter http://www.mycompany.com 2627ch23.qxd 8/22/00 11:18 AM Page 872 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 873 as the link and MyCompany Home Page as the label. Doing so would create a link at the bottom of the Web page labeled MyCompany Home Page that would take users to www.mycompany.com. Just below that, there is a text box that will allow you to enter a Transact-SQL SELECT query to pull hyperlink information out of a SQL Server table. The table needs to be created and populated in advance, but this option can come in very handy if you have a large number of links to add to the page or if your links are always changing. FIGURE 23.14 Adding hyperlinks to your page can make other company sites easier to find. If you’re following along, please select the option to add a single link, and enter http://www.sybex.com in the Hyperlink URL textbox and Sybex Books in the Hyperlink Label textbox, then click Next. Limiting the Rows Displayed Even if you entered a WHERE clause (as seen in Figure 23.7 earlier in this chapter), you may still get too many rows. For instance, if you work for a large company and decide to display the records where the last name is Smith, you may see a large num- ber of records. On the screen shown in Figure 23.15, you can limit the number of rows displayed by SQL Server. PUBLISHING DATA WITH THE WEB ASSISTANT WIZARD Development with SQL Server PART V 2627ch23.qxd 8/22/00 11:18 AM Page 873 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. CHAPTER 23 • THE WEB ASSISTANT WIZARD 874 The first option does just as it reads by displaying all the rows in the result set. If you want to limit the number of rows, you should select the second option, labeled Yes, and then enter the number of records to be displayed on the Web page. Depending on the number of rows being displayed, you may want to split the data across several Web pages, because readers do not want to have to scroll through a large number of records at once (and larger pages take longer to download). To split the data across several pages, simply select the option at the bottom of the page that states Yes, Link the Successive Pages Together and then enter the number of records to be displayed on each page in the Limit Each Page to x Rows of Data textbox. FIGURE 23.15 You may not need to display all rows of data, but if you do, you may want to split them across multiple Web pages. In this example, you are going to leave the default of displaying all rows on a sin- gle page and click Next. The Final Page On the final screen of the Web Assistant Wizard, you will see a list of all the choices that you have made throughout the course of this Wizard; read through each choice and make sure it agrees with you. At the bottom of that laundry list, there is a button (as seen in Figure 23.16) labeled Write Transact-SQL to File, which will take all of your hard work, transform it into Transact-SQL code, and store it in a text file on your hard disk. This file can then be opened in Query Analyzer (a tool for running Transact-SQL code) and executed to re-create your Web Assistant Wizard job if the job gets damaged 2627ch23.qxd 8/22/00 11:18 AM Page 874 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 875 or deleted for some reason. This makes recovery much easier and therefore is highly recommended. FIGURE 23.16 On the last screen, you are given the option to review and save your changes. For this example, click the Write Transact-SQL to File button and save the text as nwind_emp.sql. When that is done, click Finish to create the Web page. The Steps to Create the Northwind Employees Web Page As promised, here are all of the steps used to create the Northwind Employees Web page (just in case you wanted to wait until the end): 1. Open Enterprise Manager by selecting it from the SQL Server 2000 group under Programs on the Start menu. 2. From the Tools menu, select Wizards. 3. Expand Management and double-click the Web Assistant Wizard. 4. On the welcome screen, click Next. 5. Select Northwind as the database from which to publish. 6. Name the job Northwind Employees and select Data from the Tables and Columns That I Select. 7. Select Employees as the table from the drop-down list and click the Add All but- ton to publish data from all columns, then click Next. PUBLISHING DATA WITH THE WEB ASSISTANT WIZARD Development with SQL Server PART V 2627ch23.qxd 8/22/00 11:18 AM Page 875 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. CHAPTER 23 • THE WEB ASSISTANT WIZARD 876 8. Select the All of the Rows option to publish all rows of data and click Next. 9. Select the At Regularly Scheduled Intervals choice and click Next. 10. Change the schedule for the job to every 2 minutes and click Next. 11. Select the default directory to place the Web page in and click Next. 12. Select the Yes, Help Me Format the Web Page option and click Next. 13. On the next page, change the title of the Web page to Northwind Employees, change the title of the table to Employee Listing, and click Next, leaving the rest of the choices as the default settings. 14. On the next page, instruct the Web Assistant Wizard to display the column names and use a fixed font, then click Next. 15. On the next page, add a single hyperlink to http://www.sybex.com labeled Sybex Books and click Next. 16. On the next screen, you will instruct SQL Server to display all of the rows from the result set and leave them on the same page, then click Next. 17. On the final screen, you will save all of the code to a text file by clicking the Write Transact-SQL to File button, then entering nwind_emp.sql as the file- name and clicking Save. 18. Finally, click Finish to create the Web Assistant Wizard job and Web page. Now you are ready to verify that everything was done correctly and view your Web page. Viewing the Page If you have followed along though this chapter, you should have a Web publishing job ready to go at this point. To verify this, you can do the following: 1. In Enterprise Manager (which should still be open), expand your server, then Management. 2. Under Management, select Web Publishing. 3. In the contents pane (on the right), double-click the Northwind Employees job. 4. On the Properties page, read the code to see exactly what SELECT statement is used to generate the result set being displayed on your Web page. 2627ch23.qxd 8/22/00 11:18 AM Page 876 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 877 Not only do you have an entry in the Web Publishing section of Management, you have a new job scheduled. Let’s view the job that the Web Assistant Wizard created for you: 1. In Enterprise Manager, expand the SQLServerAgent under Management and select Jobs (if you are a master job server, as discussed in Chapter 17, you need to select Local Jobs under Jobs). 2. In the contents pane, double-click the job named Northwind Employees. 3. Select the Steps tab and double-click step number 1 to view the code that creates the Web page. Notice that this is a special system stored procedure named sp_runwebtask. PUBLISHING DATA WITH THE WEB ASSISTANT WIZARD Development with SQL Server PART V 2627ch23.qxd 8/22/00 11:18 AM Page 877 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. CHAPTER 23 • THE WEB ASSISTANT WIZARD 878 4. Click Cancel and select the Schedules tab. 5. Double-click the schedule to see when the job will activate. 6. Click Cancel, then click Cancel again to return to Enterprise Manager. TIP If you want to change how often the Web page is created, you may do so from the Schedules tab of the job that creates the Web page. If you want to stop updating the Web page, you can disable the job altogether by unchecking the Enabled checkbox on the Gen- eral tab of the job’s properties. 2627ch23.qxd 8/22/00 11:18 AM Page 878 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 879 You probably want to see the fruits of your labors by viewing the Web page itself. Let’s do that now by opening it right from the directory it is stored in on your hard disk: 1. Click the Start button and select Run. 2. In the Open text box, type C:\Program Files\Microsoft SQL Server\ 80\Tools\HTML\WebPage1.htm (if you have installed SQL Server to a dif- ferent drive, please replace the C with your drive letter). 3. This will open your Web browser and display the Web page. Notice the title bar at the top, the table title just above the table, the boxes around the data (the table border), and, at the bottom, the link to Sybex Books. 4. At the top of the Web page, you will see a timestamp; wait for 2 minutes and click the Refresh button on your browser—the timestamp should be updated, indicating that the job is running every 2 minutes just as instructed. 5. Close your Web browser. Armed with this knowledge, you are now able to publish your data on the Web quickly and easily. PUBLISHING DATA WITH THE WEB ASSISTANT WIZARD Development with SQL Server PART V 2627ch23.qxd 8/22/00 11:18 AM Page 879 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. [...]... that you can do with SQL Server on the Web In the next chapter, we will look into some more powerful methods of putting your data on the Web by integrating SQL Server 2000 with Internet Information Server Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark 2627ch24.qxd 8/22/00 11:19 AM Page 881 CHAPTER 24 Integrating SQL Server with Internet Information Server F E AT U R I N... http://www.ntbugtraq.com/ Active Server Pages The simplest way to display data from SQL Server on a Web page is to use an Active Server Page that makes use of ADO In this section, we’ll review the general design of Active Server Pages (ASP pages) and then see how you can use them in conjunction with SQL Server and IIS to display SQL Server data in a Web page NOTE Because ASP stands for Active Server Pages, it would... updating the table IIS and SQL Server Security At this point, it’s worth taking a look at how IIS and SQL Server interact from a security point of view If you install IIS and SQL Server, create an ASP page that uses ADO to retrieve data from SQL Server, and try to load the page, you’ll get an error message similar to this one instead of your data: Microsoft OLE DB Provider for SQL Server (0x80040E4D) Login... objConnection Dim rstAuthors strConnection = “Provider=SQLOLEDB;Data Source=HENHOUSE;➥ Database=pubs;Integrated Security=SSPI” Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark Development with SQL Server V 2627ch24.qxd 892 8/22/00 11:19 AM Page 892 CHAPTER 24 • INTEGRATING SQL SERVER WITH INTERNET INFORMATION SERVER Set objConnection = Server. CreateObject(“ADODB.Connection”) objConnection.Open... strConnection Dim objConnection Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark Development with SQL Server Listing 24.1 shows the complete code for this ASP page 2627ch24.qxd 896 8/22/00 11:19 AM Page 896 CHAPTER 24 • INTEGRATING SQL SERVER WITH INTERNET INFORMATION SERVER Dim strSQL Dim rstAuthors strConnection = “Provider=SQLOLEDB;Data Source=HENHOUSE; ➥ Database=pubs;Integrated... objConnection Dim rstAuthors Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark Development with SQL Server 2627ch24.qxd 2627ch24.qxd 890 8/22/00 11:19 AM Page 890 CHAPTER 24 • INTEGRATING SQL SERVER WITH INTERNET INFORMATION SERVER strConnection = “Provider=SQLOLEDB;Data Source=HENHOUSE; ➥ Database=pubs;Integrated Security=SSPI” Set objConnection = Server. CreateObject(“ADODB.Connection”)... the operating system account as a SQL Server user is worthwhile To do this, include Integrated Security=SSPI in your OLE DB connection string Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark PA R T V Development with SQL Server 2627ch24.qxd 2627ch24.qxd 902 8/22/00 11:19 AM Page 902 CHAPTER 24 • INTEGRATING SQL SERVER WITH INTERNET INFORMATION SERVER Once everything is set up,... Microsoft Internet Information Server, and some do not, but they all require you to be running a Web server of one variety or another We’ll concentrate on IIS because it’s closely integrated with Windows and should be available to most SQL Server installations What Is Internet Information Server? Internet Information Server (IIS) is a Web server application In particular, it’s the Web server application designed... Information Server? 882 Active Server Pages 884 Remote Data Service 900 Returning Results as XML 910 Querying SQL Server through HTTP 912 Summary 919 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark 2627ch24.qxd 8/22/00 11:19 AM Page 882 I n the last chapter, you saw that the Web Assistant Wizard makes it easy to generate HTML pages from data stored in a SQL Server database... purchase PDF Split-Merge on www.verypdf.com to remove this watermark PA R T V Development with SQL Server 2627ch24.qxd 2627ch24.qxd 886 8/22/00 11:19 AM Page 886 CHAPTER 24 • INTEGRATING SQL SERVER WITH INTERNET INFORMATION SERVER TABLE 24.1: COMMON HTML TAGS (CONTINUED) Tags Meaning and Table row and Page title and Underline Suppose this file is saved on your Web server . by SQL Server. PUBLISHING DATA WITH THE WEB ASSISTANT WIZARD Development with SQL Server PART V 2627ch23.qxd 8/22/00 11:18 AM Page 873 Please purchase PDF. INTERNET INFORMATION SERVER? Development with SQL Server PART V 2627ch24.qxd 8/22/00 11:19 AM Page 883 Please purchase PDF Split-Merge on www.verypdf.com to remove

Ngày đăng: 26/01/2014, 08:20

Từ khóa liên quan

Mục lục

  • CONTENTS

  • Introduction

  • PART I • INTRODUCING SQL SERVER

    • 1 Introduction to SQL Server 2000

      • Tour for DBAs

      • Tour for Developers

      • Tour for Users

      • Summary

      • 2 Overview of Database Concepts

        • Databases

        • Tables

        • Views

        • Stored Procedures

        • Ownership and Security

        • Jobs, Alerts, and Operators

        • Replication

        • Application Programming Interfaces

        • Summary

        • 3 Overview of SQL Server

          • Programs Installed with SQL Server

          • Parts of a Database

          • SQL Server Storage Concepts

          • Summary

          • 4 Database Design and Normalization

            • What Is Normalization?

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan