INF: How To Install DTS Event Handlers In Visual BasicID: Q221193
|
The Data Transformation Services (DTS) events are documented in the SQL Server Books Online for the package object, but it does not include the declarations for Visual Basic to the events. This article contains a code sample that includes the declarations for the Visual Basic events.
The following example shows the Visual Basic declaration statements for the DTS Event Handlers:
Private Sub <object>_OnError(ByVal EventSource As String, _
ByVal ErrorCode As Long, _
ByVal Source As String, _
ByVal Description As String, _
ByVal HelpFile As String, _
ByVal HelpContext As Long, _
ByVal IDofInterfaceWithError As String, _
ByRef pbCancel As Boolean)
Private Sub <object>_OnFinish(ByVal EventSource As String)
Private Sub <object>_OnProgress(ByVal EventSource As String, _
ByVal ProgressDescription As String, _
ByVal PercentComplete As Long, _
ByVal ProgressCountLow As Long, _
ByVal ProgressCountHigh As Long)
Private Sub <object>_OnQueryCancel(ByVal EventSource As String, _
ByRef pbCancel As Boolean)
Private Sub <object>_OnStart(ByVal EventSource As String)
The following steps are an example of utilizing the SQL Server DTS Event Handlers in Visual Basic.
Option Explicit
Dim WithEvents oPackage As DTS.Package
Public bCancel As Boolean
Next, add the type library reference for DTS objects that allows you to create a DTS.Package. From the Tools menu, choose References and select Microsoft DTSPackage Object Library.
Public Sub ChangeAllStepsToRunOnMainThread(oPkg As DTS.Package)
Dim nStepCount As Integer
For nStepCount = 1 To oPkg.Steps.Count
oPkg.Steps(nStepCount).ExecuteInMainThread = True
Next nStepCount
End Sub
Private Sub oPackage_OnError(ByVal EventSource As String, _
ByVal ErrorCode As Long, _
ByVal Source As String, _
ByVal Description As String, _
ByVal HelpFile As String, _
ByVal HelpContext As Long, _
ByVal IDofInterfaceWithError As String, _
ByRef pbCancel As Boolean)
Debug.Print "oPackage_OnError Fired"
End Sub
Private Sub oPackage_OnFinish(ByVal EventSource As String)
Debug.Print "oPackage_OnFinish Fired"
End Sub
Private Sub oPackage_OnProgress(ByVal EventSource As String, _
ByVal ProgressDescription As String, _
ByVal PercentComplete As Long, _
ByVal ProgressCountLow As Long, _
ByVal ProgressCountHigh As Long)
' The DTS Package will trigger this event at certain intervals
' to report the progress of the package. This can be controlled
' by setting the DTS.Package.ProgressRowCount property.
Debug.Print "oPackage_OnProgress Fired"
End Sub
Private Sub oPackage_OnQueryCancel(ByVal EventSource As String, _
ByRef pbCancel As Boolean)
' The DTS package will trigger this event at certain intervals to check
' whether the execution of the package should be terminated. Set
' pbCancel to true to cancel the execution of the package.
Debug.Print "oPackage_OnQueryCancel Fired"
If bCancel Then
pbCancel = True
Debug.Print "Canceling package execution."
Else
pbCancel = False
End If
End Sub
Private Sub oPackage_OnStart(ByVal EventSource As String)
Debug.Print "oPackage_OnStart Fired"
End Sub
Private Sub Command1_Click()
Dim oTask As DTS.DataPumpTask
Dim strFileName As String
Dim strFilePassword As String
bCancel = False
Set oPackage = New DTS.Package
strFileName = "C:\temp\test.dts"
'strFilePassword = "VerySecurePassword" 'Use if file has password
oPackage.LoadFromStorageFile strFileName, strFilePassword
'For x = 1 To oPackage.Tasks.Count
' Debug.Print oPackage.Tasks.Item(x)
'Next x
' Only call the following when developing the application. You
' can comment out the call when you build your application.
ChangeAllStepsToRunOnMainThread oPackage
Set oTask = oPackage.Tasks.Item("DTSTask_DTSDataPumpTask_1").CustomTask
oTask.ProgressRowCount = 1
Screen.MousePointer = vbHourglass
oPackage.Execute
Screen.MousePointer = vbNormal
Set oTask = Nothing
Set oPackage = Nothing
End Sub
RESULTS
==============================
oPackage_OnStart Fired
oPackage_OnProgress Fired
oPackage_OnQueryCancel Fired
oPackage_OnProgress Fired
oPackage_OnQueryCancel Fired
...
--omitted for brevity
...
oPackage_OnProgress Fired
oPackage_OnQueryCancel Fired
oPackage_OnFinish Fired
oPackage_OnQueryCancel Fired
Additional query words:
Keywords : SSrvProg SSrvVisB kbSQLServ700
Version : winnt:7.0
Platform : winnt
Issue type : kbinfo
Last Reviewed: May 25, 1999