- •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
Session 29—Migrating From ASP to ASP.NET |
297 |
|
|
|
|
VBScript in ASP |
VB .NET in ASP.NET |
|
‘Do Something |
‘Do Something |
|
|
|
|
‘Raise a Fake Error |
‘Raise a Fake Error |
|
|
|
|
Err.Raise(1000) |
Err.Raise(1000) |
|
|
|
|
if Err.Number=0 Then |
Catch |
|
|
|
|
WriteFile=”No Errors” |
Return “Error Number “ & Err.Number &” was |
|
|
raised.” |
|
|
|
|
Else |
|
|
|
|
|
WriteFile= Err.Number & “ was raised.” |
|
|
|
|
|
End If |
End Try |
|
|
|
|
End Function |
End Function |
|
|
|
|
No more set
In VBScript, you often declare a variable as an object, then use the Set statement to assign it to an instance of a COM object. Neither the use of Set in this fashion nor the use of Let statements are supported in VB .NET.
Arguments are now passed ByVal as default
A subtle change that is going to cause a lot of headaches for you is that most parameters are passed by value as the default. This is the exact opposite of VB6. For example, take a procedure such as:
Function add(A As Int, B As Int)
A=A+B
Return A
End Function
When you use it in VB .NET as add(C, D) you will discover that neither of the input variables C or D is modified by the procedure.
Running ASP Pages under Microsoft.NET
As we mentioned earlier, you can operate your ASP pages side by side with your ASP.NET pages. You should consider several other factors when operating a portion of your application in ASP and the other portion on ASP.NET:
Session variables are not natively shared between ASP and ASP.NET pages.
You will not have access to the ADO.NET components from ASP.
298 |
Sunday Afternoon |
You should maintain your security framework in ASP.
Avoid mixing ASP and ASP.NET if you are building .NET applications for distribution.
Assuming that you are not making extensive use of session variables and are not planning on redistributing the application, then mixing your ASP and ASP.NET pages should be fairly straightforward.
Using VB6 Components with ASP.NET
In the next session, we will examine how you can use VB6 components — or for that matter any unmanaged code — in your ASP.NET applications. Additionally we will show how you can use these components via early binding using the TlbImp.exe utility.
The type library importer utility (TlbImp.exe) is responsible for converting the type definitions found within a COM type library into equivalent definition in .NET runtime metadata format. A detailed documentation of the utility can be found in the .NET documentation.
REVIEW
We have covered at a high level the major differences in ASP and ASP.NET. Overall you probably have the feeling that there is quite a bit of rework to perform in order to successfully migrate to ASP.NET. We hope, however, that you do appreciate the significant benefits that can be obtained through this migration effort.
QUIZ YOURSELF
1.How is the rendering of HTML objects handled in ASP.NET? (See “Rendering HTML page elements.”)
2.What is a script block? (See “Using script blocks.”)
3.Can you early bind VB6 components in ASP.NET? (See “Using VB6 Components with ASP.NET.”)
S E S S I O N
30
Migrating from ADO to ADO.NET
Session Checklist
Modifying code to run ADO under ASP.NET
Early binding ADO COM objects in ASP.NET
Understanding performance issues of using ADO under the .NET Framework
In this session, we look at what is required to begin the migration of your existing ADO code to the .NET Framework. These options range from straight code migration to employing early binding to full migration of your ADO business objects to ADO.NET.
Preparing a Migration Path
ADO.NET is a very different animal from ADO. Migrating to ADO.NET from ADO is not a path well traveled at this point, nor is it one that should be taken lightly. But ADO.NET is a critical piece of the ASP.NET Framework; and, like ADO itself, ADO.NET is likely to become a common data access footprint. If you are choosing the ASP.NET platform as your development platform, then you should plan on adopting ADO.NET to support your data handling code.
Because the ADO.NET platform is significantly different from the ADO solution, do not underestimate the time required to perform a migration. Unlike ASP code, which can be ported to ASP.NET with relatively few modifications, ADO.NET provides no such luxury. In fact, it is possible that you will first begin your migration to ASP.NET by migrating your ASP VBScript or JScript to ASP.NET and continuing to run your ADO code as is. So, yes, it is possible to execute your ADO code in an ASP.NET page, with some limitations.
When you are comfortable operating in the .NET Framework, then you should begin the process of looking at how to transform your ADO code to ADO.NET. A few things should guide your thinking when preparing for this task:
300 |
Sunday Afternoon |
Forget about how your ADO code operates and remove any preconceptions about how it should translate into ADO.NET.
Go back to the design of your data access components and begin mapping the design to the new ADO.NET model. Look at the features provided and determine if the cost in relation to the benefit is worth the migration.
As you migrate data tier objects, focus first on those objects providing the lowest risk and highest benefit. Because you can operate ASP and ASP.NET as well as ADO and ADO.NET in the same environment, you don’t have to force yourself into a big bang migration step. Instead, you can make the migration incrementally.
In the next sections, we look at how you can migrate your ADO code to the ASP.NET Framework.
ADO and ADO.NET Compatibility
We have covered much of the new functionality offered in the ADO.NET object model and its advantages and disadvantages in the .NET Framework. Table 30-1 offers a useful summary of some of the essential compatibility differences that you should be aware of when attempting to decide when and how you will begin the migration of your ADO code to ADO.NET. The table provides a description of the key differences in major features of the two data access frameworks to help guide your thinking when deciding what to upgrade.
Table 30-1 Comparing Features of ADO and ADO.NET |
|
|
Feature |
ADO |
ADO.NET |
Data storage |
Uses the RecordSet object, |
DataSet object may consist of |
and presentation |
which may contain multiple |
collections of one or more |
|
result sets to store the |
Database Tables, Relationships, |
|
results for multiple tables |
and Constraints that form a |
|
|
memory-resident database |
|
|
|
Relationships between |
Supports the use of the |
Supports the DataRelation object |
multiple tables |
SHAPE provider to build |
to associate rows in one DataTable |
|
hierarchical RecordSet, or |
object with rows in another |
|
requires the use of a JOIN |
DataTable object |
|
query to create a view from |
|
|
multiple database tables in |
|
|
a single result table |
|
|
|
|
Access to individual |
Scans rows sequentially |
Uses a navigation approach for |
rows of a data set |
|
nonsequential access to each row |
|
|
in a table. Has the capability to |
|
|
follow hierarchical relationships to |
|
|
navigate from rows in one table to |
|
|
related rows in another table |
|
|
|
Session 30—Migrating from ADO to ADO.NET |
301 |
|
|
|
|
Feature |
ADO |
ADO.NET |
Support for |
Provided by the RecordSet |
Supported for forward-only |
server-side cursors |
object through setting |
execution via the DataReader. |
|
the Connection Object |
DataReader can also execute SQL |
|
|
commands directly and handle the |
|
|
return of data rows |
Support for |
Supported in the RecordSet |
Disconnected Data |
object but typically supports |
Access |
connected access, represented |
|
by the Connection object. |
|
Communication to a database |
|
occurs through the OLE DB |
|
provider |
The DataSet object supports disconnected data access by storing data in XML
Support for passing |
By default uses COM |
data between providers |
marshaling to transmit |
and consumers, tiers |
a disconnected record set, |
or components |
effectively limiting this |
|
capability to COM |
|
environments. Limited |
|
capability to store data as |
|
an XML file and then use |
|
manual programmatic tasks |
|
to transport to non COM |
|
oriented consumers |
All transports occur with an XML file, and provide ability to transport schemas via XSD
Support for |
Not natively supported in |
transferring data |
the RecordSet object. |
across firewalls. |
Transport can occur through |
|
the use of COM Internet |
|
Services (CIS) plus |
|
Distributed Component Object |
|
Model (DCOM), Remote Data |
|
Services (RDS), use of the |
|
SOAP Toolkit or remote |
|
scripting, all of which provide |
|
their own complications in |
|
terms of requirements on |
|
the consumer side of the |
|
transaction or complexity of |
|
support on the server side |
Fully supported with WebServices leveraging SOAP and XML as the envelope and HTTP as the transport
Continued