RE: Running DTS Custom Task from VB .Net -
05-31-2005
, 08:20 AM
FYI, here's the code, which works fine without the custom task in the DTS.
Private Sub btnLoadBatchSecurityRequests_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btnLoadBatchSecurityRequests.Click
Dim dtsLoadBatchRequests As DTS.Package
Dim strFormName As String = ""
Dim strErrorMessage As String = ""
Dim connSQL As SqlConnection
Dim cmdSQL As SqlCommand
Dim strSQLConnection As String =
ConfigurationSettings.AppSettings("DSN")
lblBatchLoaded.Visible = True
lblBatchLoaded.ForeColor = Color.Red
lblBatchLoaded.Text = "Batch Loading !"
Try
dtsLoadBatchRequests = New DTS.Package
'Begin - set up events sink
Dim cpContainer As UCOMIConnectionPointContainer
cpContainer = CType(dtsLoadBatchRequests,
UCOMIConnectionPointContainer)
Dim cpPoint As UCOMIConnectionPoint
Dim PES As PackageEventsSink = New PackageEventsSink
Dim guid As Guid = _
New Guid("10020605-EB1C-11CF-AE6E-00AA004A34D5")
cpContainer.FindConnectionPoint(guid, cpPoint)
Dim intCookie As Integer
cpPoint.Advise(PES, intCookie)
'End - set up events sink
' Load and execute DTS package
connSQL = New SqlConnection(strSQLConnection)
connSQL.Open()
dtsLoadBatchRequests.LoadFromSQLServer(connSQL.Dat aSource,
"blahblahblah", "blahblahblah", _
DTSSQLServerStorageFlags.DTSSQLStgFlag_Default, _
"", "", "", "PCANetWeb - Batch Security Requests", Nothing)
dtsLoadBatchRequests.Execute()
' End - Load and execute DTS package
dtsLoadBatchRequests.UnInitialize()
dtsLoadBatchRequests = Nothing
cpPoint.Unadvise(intCookie)
cpPoint = Nothing
cpContainer = Nothing
PES = Nothing
lblBatchLoaded.ForeColor = Color.Green
lblBatchLoaded.Text = "Batch Loaded Successfully !"
Catch exc As Exception
strFormName = Server.HtmlEncode("Load Batch Requests")
strErrorMessage = Server.HtmlEncode("Batch Load Failed. Please
contact Customer Care.")
Response.Redirect("../intranet/form_deny.asp?form_name=" &
strFormName & Chr(38) & "error_message=" & strErrorMessage)
Finally
End Try
End Sub
Public Class PackageEventsSink
Implements DTS.PackageEvents
Overridable Overloads Sub OnError(ByVal EventSource As String, _
ByVal ErrorCode As Integer, ByVal Source As String, _
ByVal Description As String, ByVal HelpFile As String, _
ByVal HelpContext As Integer, ByVal IDofInterfaceWithError
As String, _
ByRef pbCancel As Boolean) Implements
DTS.PackageEvents.OnError
End Sub
Overridable Overloads Sub OnFinish(ByVal EventSource As String) _
Implements DTS.PackageEvents.OnFinish
End Sub
Overridable Overloads Sub OnProgress(ByVal EventSource As String, _
ByVal ProgressDescription As String, ByVal PercentComplete
As Integer, _
ByVal ProgressCountLow As Integer, ByVal ProgressCountHigh
As Integer) _
Implements DTS.PackageEvents.OnProgress
End Sub
Overridable Overloads Sub OnQueryCancel(ByVal EventSource As String, _
ByRef pbCancel As Boolean) Implements
DTS.PackageEvents.OnQueryCancel
pbCancel = False
End Sub
Overridable Overloads Sub OnStart(ByVal EventSource As String) _
Implements DTS.PackageEvents.OnStart
End Sub
End Class |