Tải bản đầy đủ (.pdf) (50 trang)

Microsoft SQL Server 2000 Data Transformation Services- P6

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (429.75 KB, 50 trang )

.ExceptionFileOptions = 1 ‘DTSExcepFile_SingleFile70
.ExceptionFileRowDelimiter = “{CR}{LF}”
.ExceptionFileTextQualifier = “”
.FetchBufferSize = 1
.FirstRow = 0
.InputGlobalVariableNames = “”
.LastRow = 0
.MaximumErrorCount = 0
.ProgressRowCount = 1000
.SourceSQLStatement = “”
End With
pkg.Tasks.Add tsk
‘Create step for task
Set stp = pkg.Steps.New
With stp
.Name = “stp” & sBaseName
.Description = sBaseName
.TaskName = tsk.Name
End With
pkg.Steps.Add stp
fctCreateDataDrivenQueryTask = stp.Name
Set conSource = Nothing
Set conDest = Nothing
Set tsk = Nothing
Set cus = Nothing
Set stp = Nothing
ProcExit:
Exit Function
ProcErr:
MsgBox Err.Number & “ - “ & Err.Description
GoTo ProcExit


End Function
Conclusion
The Data Driven Query task is a useful tool when you need to specify multiple results for a
data transformation. The next chapter explains how to use multiple phases with the transforma-
tion tasks.
DTS Connections and the Data Transformation Tasks
P
ART
II
226
L
ISTING
8.2
Continued
11 0672320118 CH08 11/13/00 4:56 PM Page 226
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
CHAPTER
9
The Multiphase Data Pump
IN THIS CHAPTER
• Enabling the Multiphase Data Pump 228
•Programmatic Flow with Multiple Phases 230
• Using the Phases 233
•Creating a COM Object with Visual C++ to
Program the Phases 243
•Creating a Multiphase Data Pump in
Code 243
12 0672320118 CH09 11/13/00 5:03 PM Page 227
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
DTS Connections and the Data Transformation Tasks

P
ART
II
228
The multiphase data pump option allows you to write code at several different points in the
data transformation process. You can use this option with the Transform Data task, the Data
Driven Query task, and the Parallel Data Pump task.
If you haven’t enabled the multiphase data pump, you can write code for only one point of the
data transformation process—the point at which each row is being transformed. After enabling
this option, you can write code for all these phases and subphases:
•Pre Source Phase—Before the source query is executed.
•Row Transform Phase—Each row of data is processed.
• On Transform Failure—Subphase of the Post Row Transform phase. Occurs when there
is an error in the transformation.
• On Insert Failure—Subphase of the Post Row Transform phase. Occurs when a record
fails to be inserted.
• On Insert Success—Subphase of the Post Row Transform phase. Occurs when a record is
successfully inserted.
• Batch Complete Phase—A batch of records is successfully inserted.
• Post Source Data Phase—The rows have all been processed.
• Pump Complete Phase—The transformation task has completed its work.
Enabling the Multiphase Data Pump
The last section of this chapter explains how to create a multiphase data pump in code. In the
DTS Designer, you can enable the multiphase data pump by doing the following:
1. Right-click on the Data Transformation Services node in the Enterprise Manager.
2. Select Properties from the pop-up menu.
3. Select Show multi-phase pump in DTS Designer on the Package Properties dialog, as
shown in Figure 9.1.
After selecting the multiphase option, you will see a Phases filter on the Transformation tab of
the Transform Data Task Properties dialog, as shown in Figure 9.2. Each transformation can

implement one or more of the phases. By selecting one of the phases, you can see which trans-
formations have implemented a particular phase.
The Phases tab of the ActiveX Script Transformation Properties dialog shows the eight phases
and subphases where you can write code, as shown in Figure 9.3. You enable a phase by select-
ing the check box beside it. You can set the default entrance function and create the default
code for all the phases you have selected by clicking the Auto Gen button.
12 0672320118 CH09 11/13/00 5:03 PM Page 228
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
F
IGURE
9.1
You select the multiphase data pump option in the Package Properties dialog.
The Multiphase Data Pump
C
HAPTER
9
9
T
HE
M
ULTIPHASE
D
ATA
P
UMP
229
F
IGURE
9.2
You can use the Phases filter to show the transformations that are using a particular phase.

Even if you remove the multiphase option from the Package Designer, multiple
phases in a transformation will remain. However, you will not be able to view all the
properties of those transformations in the Package Designer without using Disconn-
ected Edit. If any of your transformations do not include a Row Transform phase, you
will not be able to access that phase in the Transform Data Task Properties dialog.
N
OTE
12 0672320118 CH09 11/13/00 5:03 PM Page 229
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
DTS Connections and the Data Transformation Tasks
P
ART
II
230
F
IGURE
9.3
You can choose which phases you want to use in the ActiveX Script Transformation Properties dialog.
You can enable the multiphase data pump option in code by using the Application object.
Here’s the VBScript code to do so:
Function Main
Dim app
Set app = CreateObject(“DTS.Application”)
app.DesignerSettings = DTSDesigner_ShowMultiPhaseTransforms
Main = DTSTaskExecResult_Success
End Function
Programmatic Flow with Multiple Phases
Figure 9.4 shows the programmatic flow of the phases and subphases as the Transform Data
task is executed. You can choose to implement one, all, or any combination of these phases and
subphases. When you implement a phase, the specified entry function is called and the code in

that function is executed.
The Pre Source phase is usually executed just once. You can execute it more than once by set-
ting
DTSTransformStat_SkipFetch
as the return value from the entry function.
The Row Transform phase is executed once for each record in the data source.
12 0672320118 CH09 11/13/00 5:03 PM Page 230
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
F
IGURE
9.4
The programmatic flow in the multiphase data pump.
The Post Row Transform phase is often executed once for each record in the data source. It is
not executed if the Row Transform phase is completed successfully, and it does not attempt to
insert a record into the destination.
The Transform Failure subphase is executed whenever there is an error in the Row Transform
phase.
Either the Insert Success subphase or the Insert Failure subphase is executed after an attempt
to insert a record into the destination. These subphases are mutually exclusive.
The On Batch Complete phase is executed once each time a batch of records is committed.
This phase is only used when Fast Load is being used.
The Post Source Data and Pump Complete phases are each executed once after all the records
have been processed.
Information about the progress of the transformation is available through the properties of the
DTSTransformPhaseInfo
object. This object can be referenced both from the code of the trans-
formation and from code in a transformation ActiveX script.
The Multiphase Data Pump
C
HAPTER

9
9
T
HE
M
ULTIPHASE
D
ATA
P
UMP
231
On Insert Failure On Insert Success
OK/SkipFetch Skip Row/Skip Insert
Error/Exception No Error
On Transform
Failure
Row Transform
Batch Complete
Pump Complete
Pre Source
Post Source
Skip Fetch
All Rows Processed Follow Next Row in Batch/Skip Fetch
Follow Next Row after Batch
Post Row
12 0672320118 CH09 11/13/00 5:03 PM Page 231
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
All six properties of the
DTSTransformPhaseInfo
object are read-only. They are as follows:


CurrentPhase
—The phase whose code is currently being executed. This property uses
the values of the
DTSTransformPhaseEnum
, which are listed in the last section of this
chapter.

CurrentSourceRow
—The number of the source row currently being processed. The
source rows are numbered consecutively, beginning with 1.

DestinationRowsComplete
—The number of rows that have been successfully inserted
into the data destination. For a Data Driven Query task, the value in this property is the
number of data-driven queries that have been executed.

ErrorRows
—The number of rows that have generated an error.

ErrorCode
—The error code returned by the phase immediately preceding the current
phase.

TransformStatus
—The transformation status returned by the transformation immedi-
ately preceding the current transformation, when that transformation was executed on the
same row of source data.
Three of these properties (CurrentSourceRow, DestinationRowsComplete, and ErrorRows) use
the

vt_decimal
data type. When you reference these properties in VBScript, you have to con-
vert them to long integers:
lCurrentSourceRow = CLng(DTSTransformPhaseInfo.CurrentSourceRow)
Listing 9.1 shows a function that uses several of these properties to record the state of the
transformation at the time of an error. You can find this code in a file called UseAllPhases.dts
on the book’s CD.
L
ISTING
9.1
The Properties of the DTSTransformPhaseInfo Object Can Help Determine
What Happened at the Time of an Error
Function fctError
Dim msg, sPhase
sPhase = fctPhaseName
If bDisplayErrMsg Then
msg = “Error in “ & sPhase & vbCrLf
msg = msg & Err.Number & “ “ & Err.Description
msgbox msg
End If
If bRecordErr Then
DTSLookups(“InserttblOrderErrors”).Execute _
DTS Connections and the Data Transformation Tasks
P
ART
II
232
12 0672320118 CH09 11/13/00 5:03 PM Page 232
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
DTSSource(“OrderID”), _

DTSSource(“TranType”), _
DTSSource(“TranDate”), _
DTSDestination(“OrderID”), _
DTSDestination(“OrderDate”), _
DTSDestination(“RequiredDate”), _
DTSDestination(“ShippedDate”), _
DTSTransformPhaseInfo.CurrentPhase, _
CLng(DTSTransformPhaseInfo.CurrentSourceRow) , _
DTSTransformPhaseInfo.ErrorCode, _
CLng(DTSTransformPhaseInfo.DestinationRowsComplete) , _
DTSTransformPhaseInfo.TransformStatus, _
Now, _
Err.Number, _
Err.Description
End If
End Function
Using the Phases
The phases and subphases differ in their access to the source and destination columns. They
also have different return values that are valid for the entry function. Table 9.1 has an overview
of these differences. (Where my testing varies from Books Online, the information from Books
Online appears in parentheses.)
T
ABLE
9.1
The Columns and the Return Values Available for Each of the Phases
Phase/Subphase Source Columns Destination Columns Return Values
Pre Source None Write All
Row Transform Read Write All
Transform Failure Read Write All
Insert Failure Read Write(None) OK or AbortPump

Insert Success Read Write(None) OK or AbortPump
Batch Complete Read(None) Read(None) OK or AbortPump
Post Source Data None Write All
Pump Complete Read(None) Read(None) OK or AbortPump
The Multiphase Data Pump
C
HAPTER
9
9
T
HE
M
ULTIPHASE
D
ATA
P
UMP
233
L
ISTING
9.1
Continued
12 0672320118 CH09 11/13/00 5:03 PM Page 233
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
Books Online states that the Pre Source phase, the Transform Failure subphase, and the Post
Source Data phase can use all the transformation values that can be returned from a Row
Transform phase.
DTS Connections and the Data Transformation Tasks
P
ART

II
234
The transformation statuses have some different behavior when used for the various
phases:
DTSTransformStat_SkipFetch
can be used as the return value for the Pre Source
phase, the Transform Failure subphase, and the Post Source Data phase, as well as for
the Row Transform phase. For all of these phases, this transformation status causes
the phase’s entry function to be called again immediately.
DTSTransformStat_SkipInsert
has the same effect as
DTSTransformStat_OK
when
used for the Pre Source phase, the Transform Failure subphase, and the Post Source
Data phase.
DTSTransformStat_SkipRow
can be used only for the Row Transform phase. It gener-
ates an error when used for any other phase.
N
OTE
Chapter 7, “Writing ActiveX Scripts for a Transform Data Task,” has a transformation script
example that uses two of the transformation phases. I have extended that example here to use
all eight of the phases and subphases. You can find it on the CD in a file called
UseAllPhases.dts.
The transformation script has a function called
fctPhase
that displays a message box telling
which phase is currently active. The message is only displayed if the user sets the value of the
variable
bDisplayPhase

to
TRUE
in the Pre Source phase. This function calls another function,
fctPhaseName
, which finds the current phase number and converts it into a phase name. These
functions are shown in Listing 9.2.
L
ISTING
9.2
Functions That Display the Current Phase
Function fctPhase
Dim msg
If bDisplayPhase = True Then
msg = fctPhaseName
msgbox msg
End If
End Function
12 0672320118 CH09 11/13/00 5:03 PM Page 234
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
Function fctPhaseName
dim sName
Select Case DTSTransformPhaseInfo.CurrentPhase
Case 1
sName = “Pre-Source Data Phase”
Case 2
sName = “Post-Source Data Phase”
Case 4
sName = “Row Transform Phase”
Case 8
sName = “On Transform Failure Phase”

Case 16
sName = “On Insert Success Phase”
Case 32
sName = “On Insert Failure Phase”
Case 64
sName = “Batch Complete Phase”
Case 128
sName = “Pump Complete Phase”
End Select
fctPhaseName = sName
End Function
Pre Source Phase
You can use the Pre Source phase to initialize variables that are used throughout the script. You
can use either global variables or script variables declared outside a function for this purpose.
If you use script variables, they will be visible only to functions in this particular script. They
will not be visible outside the task or to other transformations in the same task.
If you are using a text file as the destination for your transformation, you could use the Pre
Source phase to write a header to the file.
If you want to execute the code in this phase more than once, you can return the
DTSTransformStat_SkipFetch
transformation value from the entry function of the Pre Source
phase.
The Multiphase Data Pump
C
HAPTER
9
9
T
HE
M

ULTIPHASE
D
ATA
P
UMP
235
L
ISTING
9.2
Continued
12 0672320118 CH09 11/13/00 5:03 PM Page 235
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
Listing 9.3 shows the script variable declarations and the code for the Pre Source phase of the
UseAllPhases example. In the Pre Source phase, you have the option of setting the display and
recording options for the task. You can display message boxes that show the current phase, the
transformation progress, or the transformation errors. You can record the progress in
tblOrderProgress and the errors in tblOrderErrors. By default, the message boxes are disabled
and the recording is enabled.
L
ISTING
9.3
The Pre Source Phase from the UseAllPhases Task
Option Explicit
Dim bDisplayProgressMsg, bRecordProgress
Dim bDisplayErrMsg, bRecordErr
Dim bDisplayPhase
Dim lLastInsertSuccessKey
Function PreSourceMain()
‘Set Display and Recording Options
bDisplayProgressMsg = CBool(False)

bRecordProgress = CBool(True)
bDisplayErrMsg = CBool(False)
DTS Connections and the Data Transformation Tasks
P
ART
II
236
You can change the source for the Transform Data task in the Pre Source phase, but
that change does not go into effect until the next time the task is executed. Even
though the Pre Source phase occurs before the first data is processed, the source
query has already been executed when this phase occurs, so changing the query has
no effect on the current execution of the task.
If you want to dynamically modify the source query for a Transform Data task, you
can do so in a Dynamic Properties task or an ActiveX Script task before the execution
of the Transform Data task. You could also modify the source query in a Workflow
ActiveX Script for the step associated with the Transform Data task.
N
OTE
You cannot access any of the transformation’s source columns in this phase. You do have
access to the destination columns, however. Any values that you assign to the destination
columns will remain until they are overwritten or until the first record is inserted into the
destination.
12 0672320118 CH09 11/13/00 5:03 PM Page 236
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
bRecordErr = CBool(True)
bDisplayPhase = CBool(False)
‘Initialize
lLastInsertSuccessKey = 0
Call fctPhase
Call fctProgress

PreSourceMain = DTSTransformstat_OK
End Function
Row Transform Phase
The Row Transform phase is the default transformation phase. Writing scripts for this phase is
the topic of Chapter 7, “Writing ActiveX Scripts for a Transform Data Task.”
You are required to have a Row Transform phase in at least one of the transformations defined
for a transformation task. All the other phases are optional.
You can modify the values in the transformation’s destination columns in most of the phases.
This is the only phase where you can actually insert rows into the data destination.
Post Row Transform Phase
You cannot write code for the Post Row Transform phase. Instead, you write code for one or
more of the subphases associated with this phase:
• On Transform Failure
• On Insert Failure
• On Insert Success
Zero, one, or two of these subphases will be called for each record being transformed. None of
the subphases will be called if the Row Transform phase is successful but returns a transforma-
tion status of
DTSTranformStat_SkipInsert
or
DTSTransformStat_SkipRow
. On Insert Failure
and On Insert Success are mutually exclusive—one and only one will be called for each
attempted insert into the data destination.
The Multiphase Data Pump
C
HAPTER
9
9
T

HE
M
ULTIPHASE
D
ATA
P
UMP
237
L
ISTING
9.3
Continued
12 0672320118 CH09 11/13/00 5:03 PM Page 237
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
On Transform Failure Subphase
If the Row Transform phase returns an error (
DTSTransformStat_Error
or
DTSTransformStat_ExceptionRow
), the On Transform Failure subphase will be called.
You have read access to the source columns and write access to the destination columns in this
phase. The UseAllPhases task uses this subphase to call
fctError
, which creates a record to
store the values of all the source and destination columns (see Listing 9.4).
L
ISTING
9.4
The On Transform Failure Subphase from the UseAllPhases Task
Function TransFailureMain()

Call fctPhase
Call fctError
TransFailureMain = DTSTransformstat_OK
End Function
On Insert Failure Subphase
The Row Transform phase may be completed successfully, but the insertion of a record into the
data destination may fail. The insert failure could be a result of one of the following:
•Violation of a Primary Key constraint
•Violation of a Foreign Key constraint
•Violation of a Unique constraint
•Violation of a Check constraint
DTS Connections and the Data Transformation Tasks
P
ART
II
238
An insert failure is not usually caused by a data type conversion error. Those errors
usually cause a transform failure.
N
OTE
You have read access to the transformation’s source columns and write access to the destina-
tion columns during this phase. It doesn’t do much good to write to these destination columns,
though, because they will be set to Null before the next execution of the Row Transform
phase.
12 0672320118 CH09 11/13/00 5:03 PM Page 238
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
The UseAllPhases task also uses this subphase to call
fctError
,as shown in Listing 9.5.
L

ISTING
9.5
The On Insert Failure Subphase from the UseAllPhases Task
Function InsertFailureMain()
Call fctPhase
Call fctError
InsertFailureMain = DTSTransformstat_OK
End Function
On Insert Success Subphase
Whenever a record is successfully inserted into the data destination, the On Insert Success sub-
phase is executed. As with the On Insert Failure subphase, you have read access to the trans-
formation’s source columns and write access to the destination columns during this subphase.
This subphase can be used to keep track of the progress of a data transformation when you are
not using Fast Load. You would normally use the On Batch Complete phase to do this, but On
Batch Complete is not executed when Fast Load is not being used.
This subphase can also be used for maintaining aggregations. As each new record is inserted
into the destination, the aggregated value can be updated. It is usually possible (and much
more efficient) to calculate aggregations after all the records have been processed.
The UseAllPhases task uses this subphase to store the value of the most recent OrderID that
has been inserted (see Listing 9.6). This value is used in the On Batch Complete phase as addi-
tional information on the progress of the transformation for the report.
The Multiphase Data Pump
C
HAPTER
9
9
T
HE
M
ULTIPHASE

D
ATA
P
UMP
239
My testing indicates that this subphase is never executed when Fast Load is used. Fast
Load greatly improves the performance of the Transform Data task. The inability to
use this subphase with Fast Load significantly reduces its value.
This problem only occurs with this subphase—On Transform Failure and On Insert
Success are executed whether or not Fast Load is being used.
C
AUTION
12 0672320118 CH09 11/13/00 5:03 PM Page 239
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
L
ISTING
9.6
The On Insert Success Subphase from the UseAllPhases Task
Function InsertSuccessMain()2
Call fctPhase
‘Save the Value for use in fctProgress.
lLastInsertSuccessKey = DTSDestination(“OrderID”)
InsertSuccessMain = DTSTransformstat_OK
End Function
On Batch Complete Phase
The On Batch Complete phase occurs when a batch is committed to the destination. This phase
is not executed when Fast Load is not being used.
Books Online states that neither the source nor the destination columns are available in this
phase. My testing indicates that they are both available for reading but not writing.
The On Batch Complete phase is useful for keeping track of the progress of a data transforma-

tion. The UseAllPhases task uses the phase for that purpose, as shown in Listing 9.7.
L
ISTING
9.7
The On Batch Complete Phase and the
fctProgress
Function from the
UseAllPhases Task
Function BatchCompleteMain()
Call fctPhase
Call fctProgress
BatchCompleteMain = DTSTransformstat_OK
End Function
Function fctProgress
Dim msg, sProgress, sPhase, lCurrentSourceRow, lDestRowsComplete
lCurrentSourceRow = CLng(DTSTransformPhaseInfo.CurrentSourceRow)
lDestRowsComplete = CLng(DTSTransformPhaseInfo.DestinationRowsComplete)
Select Case DTSTransformPhaseInfo.CurrentPhase
Case DTSTransformPhase_PreSourceData
sProgress = “Start”
Case DTSTransformPhase_OnBatchComplete
DTS Connections and the Data Transformation Tasks
P
ART
II
240
12 0672320118 CH09 11/13/00 5:03 PM Page 240
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
sProgress = “Batch Completed”
Case DTSTransformPhase_OnPumpComplete

sProgress = “Finished”
End Select
If bDisplayProgressMsg Then
sPhase = fctPhaseName
msg = “Currently in “ & sPhase & vbCRLF
msg = msg & “Progress: “ & sProgress & vbCRLF
msg = msg & “Current Source Row: “ & lCurrentSourceRow & vbCRLF
msg = msg & “Destination Rows Complete: “ & _
lDestRowsComplete & vbCRLF
msgbox msg
End If
If bRecordProgress Then
DTSLookups(“InserttblOrderProgress”).Execute _
lLastInsertSuccessKey, _
sProgress, _
lCurrentSourceRow, _
lDestRowsComplete, _
CLng(DTSTransformPhaseInfo.ErrorRows), _
Now
End If
End Function
Post Source Data Phase
The Post Source Data phase occurs after all the records have been processed. This phase is
executed only once, unless you use the
DTSTranformStat_SkipFetch
transformation value to
execute it repeatedly.
You can access the data in the transformation’s destination columns, but not in the source
columns.
You can use this phase for any final processing that needs to be accomplished on the final row

of data. The UseAllPhases task uses this phase for this purpose. The last record is inserted into
the destination, using a data modification lookup query (see Listing 9.8).
The Multiphase Data Pump
C
HAPTER
9
9
T
HE
M
ULTIPHASE
D
ATA
P
UMP
241
L
ISTING
9.7
Continued
12 0672320118 CH09 11/13/00 5:03 PM Page 241
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
L
ISTING
9.8
The Post Source Data Phase from the UseAllPhases Task
Function PostSourceMain()
On Error Resume Next
Call fctPhase
‘Insert last record

DTSLookups(“InserttblOrderDates”).Execute _
DTSDestination(“OrderID”), _
DTSDestination(“OrderDate”), _
DTSDestination(“ShippedDate”), _
DTSDestination(“RequiredDate”)
If Err.Number <> 0 Then
Call fctError
End If
PostSourceMain = DTSTransformstat_OK
End Function
DTS Connections and the Data Transformation Tasks
P
ART
II
242
If you specify a value for MaxRows that is less than the number of rows in the data
source, the Post Source Data phase code will not be executed.
C
AUTION
It appears that the final On Batch Insert phase usually occurs before the Post Source
Data phase.
N
OTE
Pump Complete Phase
The Pump Complete phase is the last phase of the data transformation. It executes only once
and cannot be called to execute again.
Books Online states that there is no access to either the source or destination columns from
this phase, but my testing indicates that there is access to both of them.
You would use the Pump Complete phase in much the same way as the Post Source Data
phase. The UseAllPhases task uses this phase to write one final record to report on the

progress of the task (see Listing 9.9).
12 0672320118 CH09 11/13/00 5:03 PM Page 242
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
L
ISTING
9.9
The Pump Complete Phase from the UseAllPhases Task
Function PumpCompleteMain()
Call fctPhase
Call fctProgress
PumpCompleteMain = DTSTransformstat_OK
End Function
Creating a COM Object with Visual C++ to
Program the Phases
If you want the best possible performance from your multiphase data pump, you should con-
sider creating a COM object with Visual C++. When you have registered your COM object,
you will be able to choose it from the list of available transformations in the Create New
Transformation dialog.
The Multiphase Data Pump
C
HAPTER
9
9
T
HE
M
ULTIPHASE
D
ATA
P

UMP
243
You cannot use Visual Basic to create a custom transformation because the data
pump library has not been made available to Visual Basic.
You can create custom tasks with Visual Basic, though.
N
OTE
See Chapter 32, “Creating a Custom Transformation with VC++,” for more information.
Creating a Multiphase Data Pump in Code
Most of the work in creating a multiphase data pump is writing the ActiveX script code for the
various phases. There are two additional things you have to do when you are creating a task
with phases using Visual Basic code—setting the
TransformPhases
property and setting the
properties that determine the entrance functions.
The
TransformPhases
Property
The
TransformPhases
property is the only extended property for the
Transformation2
object
in SQL Server 2000. This property contains a bitmap that indicates which phases are enabled
for that particular transformation. The values for the
DTSTransformPhaseEnum
constants are as
follows:
•0—
DTSTransformPhase_None

•1—
DTSTransformPhase_PreSourceData
12 0672320118 CH09 11/13/00 5:03 PM Page 243
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
•2—
DTSTransformPhase_PostSourceData
•4—
DTSTransformPhase_Transform
•8—
DTSTransformPhase_OnTransformFailure
•16—
DTSTransformPhase_OnInsertSuccess
•32—
DTSTransformPhase_OnInsertFailure
•64—
DTSTransformPhase_OnBatchComplete
• 128—
DTSTransformPhase_OnPumpComplete
• 255—
DTSTransformPhase_All
DTS Connections and the Data Transformation Tasks
P
ART
II
244
If you set the
TransformPhases
property to
DTSTransformPhase_None
, your script will

never be called. Also, you will not be able to view this script in the Transform Data
Task Properties dialog because it won’t show up for any of the phase filters.
N
OTE
Setting the Entrance Functions
You have to specify the name of the entrance function for each of the phases that you are
using. This is the function that is called when the programmatic flow reaches the point for the
particular phase. The entrance function also returns a value that determines the result of the
phase.
The entrance functions can be referenced through the
TransformServerProperties
of the
Transformation
object, as shown in Listing 9.10.
L
ISTING
9.10
VBScript Code to Reference the Names of the Entrance Functions
Option Explicit
Function Main
Dim pkg, tsk, cus, trn, trnprp
Set pkg = DTSGlobalVariables.Parent
Set tsk = pkg.Tasks(“tskAllPhases”)
Set cus = tsk.CustomTask
Set trn = cus.Transformations(“trnAllPhases”)
Set trnprp = trn.TransformServerProperties
Msgbox trnprp(“PreSourceDataFunctionEntry”)
Msgbox trnprp(“FunctionEntry”) ‘The Row Transform Phase
12 0672320118 CH09 11/13/00 5:03 PM Page 244
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.

Msgbox trnprp(“TransformFailureFunctionEntry”)
Msgbox trnprp(“InsertFailureFunctionEntry”)
Msgbox trnprp(“InsertSuccessFunctionEntry”)
Msgbox trnprp(“BatchCompleteFunctionEntry”)
Msgbox trnprp(“PostSourceDataFunctionEntry”)
Msgbox trnprp(“PumpCompleteFunctionEntry”)
Main = DTSTaskExecResult_Success
End Function
Conclusion
The multiphase data pump option allows you to extend the capabilities of your transformation
tasks. It is especially useful for error handling and monitoring the progress of the task.
The next chapter introduces the new transformation task in SQL Server 2000—the Parallel
Data Pump.
The Multiphase Data Pump
C
HAPTER
9
9
T
HE
M
ULTIPHASE
D
ATA
P
UMP
245
L
ISTING
9.10

Continued
12 0672320118 CH09 11/13/00 5:03 PM Page 245
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.

×