- •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
150 |
Saturday Afternoon |
becoming extremely fat. Originally operating as a simple way to interact with a SQL result set, the RecordSet object had grown to support disconnected sets of data, data shaping of multiple datasources, and a complex SQL generation layer that could support optimistic locking. In short, the RecordSet object was the universal data access object for COMoriented environments.
As Internet applications evolved, it became clear that their true strength would be their ability to operate as loosely coupled systems. These systems can easily communicate and exchange data across a heterogeneous environment and through an infrastructure whose primary common transmission protocol was HTTP. ADO depends heavily on COM and specifically on Advanced Data Table Gram (ADTG) as the native transmission format, which requires conversion of this binary format to derivative forms such as XML in order to support robust transmission across HTTP. ADO.NET provides the needed evolution by natively supporting XML, a text-based format, as the transmission format. This evolution provides the ability to access middle-tier business logic on any platform or standard — CORBA, COM, and so on — supporting XML, and have the services of these middle-tier applications made available to one another through the serialization and deserialization of XML for data interchange. When the transmission occurs through an XML-based standard there is a significant reduction in the amount of effort and data conversion required to access data in a heterogeneous environment.
Today’s Internet application systems need to be highly scalable and redundant. As systems scale, one of the primary limitations becomes the ability of the relational database management system (RDBMS) to maintain and support open connections to the middle-tier business objects. Typically there is a fixed limit to the number of open connections that can be supported by the RDBMS. In a distributed environment, it is likely that you will have a higher number of middle-tier components desiring simultaneous connections to the data store. To the extent that these components require an open connection for sorting, filtering, and manipulating the data, scalability is tremendously limited. ADO.NET natively supports a disconnected approach that involves pulling down the core set of data and then performing all filters, sorts, and manipulations on the middle tier. Because of its XML-based nature, it can also transmit the manipulated data set to another component for further processing before finally submitting it back to the original data store for update. In the ADO model, the extent of the disconnected manipulation was limited and thus impacted scalability — you had to programmatically handle connection opens and closes. In ADO.NET these happen automatically.
Differences between ADO and ADO.NET
The previous section discussed at a high level some of the fundamental changes in the ADO.NET framework that are driven by a move to highly distributed, loosely coupled, and thinly connected applications. This section provides a more detailed look at the differences between ADO and ADO.NET.
Transmission formats
ADO utilized a very efficient and compact binary format, the Advanced Data Table Gram (ADTG) format, to provide transmission of data between applications. This limited the direct transmission of a set of data to applications that could support this format, in this case COM applications. The transmission of data was further limited in the world of the Internet as
Session 15—Introducing ADO.NET |
151 |
there was not an easy method for sending this binary format efficiently across firewalls that often only supported HTTP. These factors effectively limit the full functional use of ADO to COM environments.
ADO.NET, by contrast, natively supports the text-based XML format for transmission of data. As a text-based, open, and widely accepted standard, XML can and is supported in COM, CORBA, and numerous other computing environments. As a text-based format, it can be readily communicated across HTTP, providing a simple method to transmit structured data across corporate firewalls.
Connected versus disconnected datasets
ADO (ActiveX Data Objects) is an application programming interface (API) for accessing data primarily in a connected (cursor-based) scenario. ADO provides the capability of using a connection-oriented approach to creating, updating, and deleting data through pessimistic locking. This is a preferred approach in a twoand three-tier environment. ADO optionally enables you to operate with a client-side cursor providing a disconnected method as well, and thus provides a solution for n-tier development.
ADO.NET is an API to access data and information in a disconnected manner. It is thus not very useful in a client/server environment, and in fact is optimized for use in a n-tier environment in which maintaining open connections to the datasource are typically inefficient and ineffective.
COM marshaling versus text-based data transmission
When operating in a purely COM environment it is clear that the ADO model provides a very rich and attractive programming interface. Its ability to use multiple cursor types and connections, and to easily shape, sort, filter, and modify data on multiple-relational and nonrelational sources is apparent. However, the ADO model is only an advantage if all systems that are interacting with each other are COM based. These very same benefits are a liability in a distributed and heterogeneous environment where mainframe, UNIX, and numerous other non-windows-based platforms are involved. In the ADO world, the transmission of a disconnected recordset from one component to another involves COM marshaling and forces the receiving component to support COM to accept the transmission. Therefore only COM objects can use ADO recordsets. And while ADO did provide the capability to save content to XML and rebuild from an external XML file, the default XML schema employed was optimized for use in an ADO environment (as opposed to transmission to non-COM based systems). With ADO.NET, the native support of XML overcomes these issues and provides an approach for transmission of almost any data type between almost any type of platform. This allows mainframe systems to communicate with COM-based middleware and then have the result modified by a CORBA-based Java Servlet while having the data roundtrip back and updating a centralized relational or nonrelational datasource.
Variant versus strongly typed data
ADO by default will utilize variant data types to comply with script-based environments. This means that the data types will not be evaluated until runtime, and that they must be evaluated prior to committing them back to the originating datasource in most cases.