- •Preface
- •Who Should Read This Book
- •Organization and Presentation
- •Contacting the Authors
- •Acknowledgments
- •Contents
- •Introduction
- •Why Microsoft .NET?
- •The Microsoft .NET Architecture
- •Internet Standards
- •The Evolution of ASP
- •The Benefits of ASP.NET
- •What Is .NET?
- •.NET Experiences
- •.NET Clients
- •.NET Services
- •.NET Servers
- •Review
- •Quiz Yourself
- •Installation Requirements
- •Installing ASP.NET and ADO.NET
- •Installing the .NET Framework SDK
- •Testing Your Installation
- •Support for .NET
- •Review
- •Quiz Yourself
- •Designing a Database
- •Normalization of Data
- •Security Considerations
- •Review
- •Quiz Yourself
- •Creating a Database
- •Creating SQL Server Tables
- •Creating a View
- •Creating a Stored Procedure
- •Creating a Trigger
- •Review
- •Quiz Yourself
- •INSERT Statements
- •DELETE Statements
- •UPDATE Statements
- •SELECT Statements
- •Review
- •Quiz Yourself
- •The XML Design Specs
- •The Structure of XML Documents
- •XML Syntax
- •XML and the .NET Framework
- •Review
- •Quiz Yourself
- •ASP.NET Events
- •Page Directives
- •Namespaces
- •Choosing a Language
- •Review
- •Quiz Yourself
- •Introducing HTML Controls
- •Using HTML controls
- •How HTML controls work
- •Intrinsic HTML controls
- •HTML Control Events
- •The Page_OnLoad event
- •Custom event handlers
- •Review
- •Quiz Yourself
- •Intrinsic Controls
- •Using intrinsic controls
- •Handling intrinsic Web control events
- •List Controls
- •Rich Controls
- •Review
- •Quiz Yourself
- •Creating a User Control
- •Adding User Control Properties
- •Writing Custom Control Methods
- •Implementing User Control Events
- •Review
- •Quiz Yourself
- •Common Aspects of Validation Controls
- •Display property
- •Type Property
- •Operator Property
- •Using Validation Controls
- •RequiredFieldValidator
- •RegularExpressionValidator
- •CompareValidator
- •RangeValidator
- •CustomValidator
- •ValidationSummaryx
- •Review
- •Quiz Yourself
- •Maintaining State Out of Process for Scalability
- •No More Cookies but Plenty of Milk!
- •Out of Process State Management
- •Review
- •Quiz Yourself
- •Introducing the Key Security Mechanisms
- •Web.config and Security
- •Special identities
- •Using request types to limit access
- •New Tricks for Forms-based Authentication
- •Using the Passport Authentication Provider
- •Review
- •Quiz Yourself
- •ASP.NET Updates to the ASP Response Model
- •Caching with ASP.NET
- •Page Output Caching
- •Absolute cache expiration
- •Sliding cache expiration
- •Fragment Caching
- •Page Data Caching
- •Expiration
- •File and Key Dependency and Scavenging
- •Review
- •Quiz Yourself
- •A Brief History of Microsoft Data Access
- •Differences between ADO and ADO.NET
- •Transmission formats
- •Connected versus disconnected datasets
- •COM marshaling versus text-based data transmission
- •Variant versus strongly typed data
- •Data schema
- •ADO.NET Managed Provider Versus SQL Managed Provider
- •Review
- •Quiz Yourself
- •Review
- •Quiz Yourself
- •Creating a Connection
- •Opening a Connection
- •Using Transactions
- •Review
- •Quiz Yourself
- •Building a Command
- •Connection property
- •CommandText property
- •CommandType property
- •CommandTimeout property
- •Appending parameters
- •Executing a Command
- •ExecuteNonQuery method
- •Prepare method
- •ExecuteReader method
- •Review
- •Quiz Yourself
- •Introducing DataReaders
- •Using DataReader Properties
- •Item property
- •FieldCount property
- •IsClosed property
- •RecordsAffected property
- •Using DataReader Methods
- •Read method
- •GetValue method
- •Get[Data Type] methods
- •GetOrdinal method
- •GetName method
- •Close method
- •Review
- •Quiz Yourself
- •Constructing a DataAdapter Object
- •SelectCommand property
- •UpdateCommand, DeleteCommand, and InsertCommand properties
- •Fill method
- •Update method
- •Dispose method
- •Using DataSet Objects
- •DataSetName property
- •CaseSensitive property
- •Review
- •Quiz Yourself
- •Constructing a DataSet
- •Tables property
- •TablesCollection Object
- •Count property
- •Item property
- •Contains method
- •CanRemove method
- •Remove method
- •Add method
- •DataTable Objects
- •CaseSensitive property
- •ChildRelations property
- •Columns property
- •Constraints property
- •DataSet property
- •DefaultView property
- •ParentRelations property
- •PrimaryKey property
- •Rows property
- •Dispose method
- •NewRow method
- •Review
- •Quiz Yourself
- •What Is Data Binding?
- •Binding to Arrays and Extended Object Types
- •Binding to Database Data
- •Binding to XML
- •TreeView Control
- •Implement the TreeView server control
- •Review
- •Quiz Yourself
- •DataGrid Control Basics
- •Binding a set of data to a DataGrid control
- •Formatting the output of a DataGrid control
- •Master/Detail Relationships with the DataGrid Control
- •Populating the Master control
- •Filtering the detail listing
- •Review
- •QUIZ YOURSELF
- •Updating Your Data
- •Handling the OnEditCommand Event
- •Handling the OnCancelCommand Event
- •Handling the OnUpdateCommand Event
- •Checking that the user input has been validated
- •Executing the update process
- •Deleting Data with the OnDeleteCommand Event
- •Sorting Columns with the DataGrid Control
- •Review
- •Quiz Yourself
- •What Is Data Shaping?
- •Why Shape Your Data?
- •DataSet Object
- •Shaping Data with the Relations Method
- •Review
- •Quiz Yourself
- •OLEDBError Object Description
- •OLEDBError Object Properties
- •OLEDBError Object Methods
- •OLEDBException Properties
- •Writing Errors to the Event Log
- •Review
- •Quiz Yourself
- •Introducing SOAP
- •Accessing Remote Data with SOAP
- •SOAP Discovery (DISCO)
- •Web Service Description Language (WSDL)
- •Using SOAP with ASP.NET
- •Review
- •Quiz Yourself
- •Developing a Web Service
- •Consuming a Web Service
- •Review
- •Quiz Yourself
- •ASP and ASP.NET Compatibility
- •Scripting language limitations
- •Rendering HTML page elements
- •Using script blocks
- •Syntax differences and language modifications
- •Running ASP Pages under Microsoft.NET
- •Using VB6 Components with ASP.NET
- •Review
- •Quiz Yourself
- •Preparing a Migration Path
- •ADO and ADO.NET Compatibility
- •Running ADO under ASP.NET
- •Early Binding ADO COM Objects in ASP.NET
- •Review
- •Quiz Yourself
- •Answers to Part Reviews
- •Friday Evening Review Answers
- •Saturday Morning Review Answers
- •Saturday Afternoon Review Answers
- •Saturday Evening Review Answers
- •Sunday Morning Review Answers
- •Sunday Afternoon Review Answers
- •What’s on the CD-ROM
- •System Requirements
- •Using the CD with Windows
- •What’s on the CD
- •The Software Directory
- •Troubleshooting
- •ADO.NET Class Descriptions
- •Coding Differences in ASP and ASP.NET
- •Retrieving a Table from a Database
- •Displaying a Table from a Database
- •Variable Declarations
- •Statements
- •Comments
- •Indexed Property Access
- •Using Arrays
- •Initializing Variables
- •If Statements
- •Case Statements
- •For Loops
- •While Loops
- •String Concatenation
- •Error Handling
- •Conversion of Variable Types
- •Index
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