Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
ASP .NET Database Programming Weekend Crash Course - J. Butler, T. Caudill.pdf
Скачиваний:
31
Добавлен:
24.05.2014
Размер:
3.32 Mб
Скачать

164

Saturday Afternoon

Note

We should mention one more thing about the ADO.NET objects. As you can see in Figure 16-3, several classes are offered in two flavors, OLEDB and SQLClient. Two examples of this are the OLEDBConnection and SQLConnection classes. Each of these “flavors” is referred to as a Managed Provider. What does this mean? Well, if you are using SQL Server 7.0 or higher, use the SQLClient classes (that is, SQLConnection, SQLCommand, and so on), otherwise use the OLEDB classes (i.e., OLEDBConnection, OLEDBCommand). You can certainly use the OLEDB classes to access a SQL Server database, but you loose a little performance because the SQL Managed Providers communicate directly with the SQL Server internal API, skipping the intermediate level represented by OLEDB.

REVIEW

In this session, you learned about classes, objects, collections, and object models. An object is an instance of a class. An object model is a hierarchical grouping of objects that are functionally related. The ADO.NET object model provides us, as developers, with an easy-to-use

programming model to access practically any type of data store. Many of the objects that make up ADO.NET come in two flavors, ADO and SQL, which are referred to as Managed Providers. With respect to ADO.NET, a Managed Provider is effectively a class that is optimized to work with a particular type of data store.

QUIZ YOURSELF

1.What is an object model? (See session introduction.)

2.How are objects and classes related? (See session introduction.)

3.What is a Managed Provider? (See session introduction.)

P A R T

III

Saturday Afternoon

Part Review

The following set of questions is designed to provide you with feedback on how well you understood the topics covered during this part of the book. Please refer to Appendix A for the answers to each question.

1.The required field validator can be used with a label control. True/False

2.What is a regular expression that can be used to validate an e-mail address?

3.More than one validation control can be used together to validate a single user input field.

True/False

4.What version of JavaScript should be used for client-side validation?

a.1.0

b.1.1

c.2.0

d.2000

5.If browsers do not support client-side cookies, what state maintenance approach can be used?

a.Cookieless

b.Client-side

c.Server-side

d.None of the above

166

Part III—Saturday Afternoon Part Review

6.Fill in the blank: Use of SQL Server for state maintance uses ______ state maintenance.

7.List two advantages of using .NET State Server.

_________________________________________

_________________________________________

8.List two advantages of using SQL Server for state maintenance.

_________________________________________

_________________________________________

9.Fill in the blank: ______ is the process of discovering and verifying

the identity of a user or service by examining the user’s credentials and validating those credentials against some authority.

10.Fill in the blank: ______ is when an application assumes the user’s identity when the request is passed to the application from IIS.

11.What section of the config.Web file is used for storing a list of authorized users?

a.<authorization>

b.<personal>

c.<credentials>

d.None of the above

12.Fill in the blank: To deny all users access to your ASP.NET application, add a <deny users="*"/> declarations to the __________________ section of your config.Web file.

13.Which of the following forms of caching involves storing the dynamic response generated by a request in memory?

a.Page output caching

b.Fragment caching

c.Page data caching

d.None of the above

14.Which of the following forms of caching involves the storing of arbitrary objects across multiple requests?

a.Page output caching

b.Fragment caching

c.Page data caching

d.None of the above

Part III—Saturday Afternoon Part Review

167

15.How do you set the TimeSpan variable equal to zero?

16.When are the rules for expiration, dependency, and scavenging established?

17.The RecordSet is a supported object type in .NET. True/False

18.Server-side cursors are supported in .NET. True/False

19. .NET can support multiple tables and their relationships in a single object.

True/False

20.Server-side cursors negatively impact the scalability of an application, in terms of concurrent users.

True/False

21.A class is an instance of an object. True/False

22.Fill in the blank: ______ is effectively a method of developing application code based on objects in order to promote code reusability, maintainability and extensibility.

23.An object model is a hierarchical grouping of objects that provides related functionality.

True/False

24.Fill in the blank: With VB .NET the ______ keyword is used to instantiate a new object.

P A R T

IV

Saturday

Evening

Session 17

Opening a Connection

Session 18

Executing Commands

Session 19

Using DataReaders

Session 20

Introducing Datasets, Part I

S E S S I O N

17

Opening a Connection

Session Checklist

Connecting with ADO.NET

Opening a connection

Understanding transaction management with ADO.NET

Before you can access any part of a database, you need to establish a connection to it. You can use either the OleDbConnection or SqlConnection object to represent that connection. Throughout our discussion of ADO.NET, we are going to use a simple analogy to try and relate ADO.NET objects to something most people use everyday — a telephone.

This will help you visualize what is actually happening when you use the ADO.NET objects. In the telephone analogy, a connection is analogous to picking up your telephone, dialing the number, and waiting for someone on the other end to answer.

Note

For the remainder of this session, we will focus on the OLEDB Managed

Provider Connection object, OleDbConnection. The OleDbConnection and

SqlConnection objects map one to one. So, if you are using a SQL Server database and would like a moderate performance boost, you can use the

SqlConnection object.

By creating an instance of an OleDbConnection object, and specifying data sourcespecific information in its properties, you can build a predefined link between the data consumer (your ASP.NET application) and the data provider (your database). Then, once you have established the connection to the data source, you can use the connection, in concert with other ADO.NET objects, to execute commands directly against the data source, to execute stored procedures, and to retrieve and manipulate data.

The OleDbConnection object also offers you the benefit of connection pooling — a mechanism that keeps connections pooled after you have explicitly closed them. Repeatedly opening and closing connections may consume Web server resources and can be a