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

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