我想從VB.NET運行SSIS包。我可以從我打算運行的包中獲取/更改變量的值,但是我無法運行它。運行SSIS包時出錯
下面是代碼(文字在方括號中的文件路徑的[]被縮短(例如,描述),而不是字面代碼)一個SNIPPIT
Private Sub ExecuteSSIS()
'Set Location of SSIS package
Dim SSISPackagePath As String = [path to package]
'Set Location of SSIS config file
Dim SSISConfigPath As String = [path to config file]
'Create instances of DTS classes
Dim sMessage As String = ""
Dim pkg As New Package
Dim app As New Microsoft.SqlServer.Dts.Runtime.Application
Dim pkgResults As DTSExecResult
'Load SSIS package
pkg = app.LoadPackage(SSISPackagePath, Nothing)
'Setup SSIS Config
pkg.EnableConfigurations = True
pkg.ImportConfigurationFile(SSISConfigPath)
'Set SSIS global variables
pkg.Variables("User::Database1").Value = db1
pkg.Variables("User::Database2").Value = db2
pkg.Variables("User::TableName").Value = tbname
'DEBUG: Proof that DTS/SSIs variables are being manipulated
MsgBox("Variables After Change" & vbNewLine & _
"db1: " & pkg.Variables("User::Database1").Value.ToString() & vbNewLine & _
"db2: " & pkg.Variables("User::Database2").Value.ToString() & vbNewLine & _
"Tab: " & pkg.Variables("User::TableName").Value.ToString() & vbNewLine)
'Execute SSIS
pkgResults = pkg.Execute()
'Error Check 1
If pkgResults = DTSExecResult.Success Then
MsgBox("DTSExecResult: Package ran successfully")
ElseIf pkgResults = DTSExecResult.Completion Then
MsgBox("DTSExecResult: Package Completed")
ElseIf pkgResults = DTSExecResult.Failure Then
MsgBox("DTSExecResult: Package ran successfully")
ElseIf pkgResults = DTSExecResult.Canceled Then
MsgBox("DTSExecResult: Package Cancelled")
Else
MsgBox("DTSExecResult: Package Unknown Error")
End If
'Error Check 2
Dim warning As DtsWarning
If pkgResults > DTSExecResult.Success Then
For Each warning In pkg.Warnings
sMessage = "Step " & warning.SubComponent & " Failed - " & _
" - Error: " & warning.WarningCode & _
" - Source: " & warning.Source & _
" - Description: " & warning.Description
Next
End If
If Len(sMessage) > 0 Then
MsgBox("SSIS error: " & vbNewLine & sMessage)
End If
End Sub
出錯校驗1被返回包成功。錯誤檢查2返回錯誤:
Error: -2147381246
Source: -[Title of first step in SSIS package]
Description:- DTS_W_MAXIMUMERRORCOUNTREACHED. The Execution method succeeded, but the number of errors raised (2) reached the maximum allowed(1)...
編輯:(額外信息)SSIS包成功地運行時從DTSX文件或源直接調用,而是從.NET應用程序
如果不處理變量值,它成功地運行? – billinkc
如果我不操作變量,我會得到相同的錯誤 –
因此,您的代碼工作正常,您的包已損壞。我錯過了什麼嗎? – billinkc