运行SSIS包时出错

时间:2013-12-09 15:44:38

标签: .net vb.net visual-studio-2010 sql-server-2005 ssis

我正在尝试从VB.NET运行SSIS包。我可以从我打算运行的包中获取/更改变量的值,但是我无法运行它。

下面是一段代码(方括号[]中的文字被缩短(例如文件路径的描述)而不是文字代码)

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返回错误:

  

错误:-2147381246

     

资料来源: - [SSIS包中第一步的标题]

     

描述: - DTS_W_MAXIMUMERRORCOUNTREACHED。执行方法成功,但引发的错误数(2)达到允许的最大值(1)...

编辑:(额外信息)SSIS包直接从DTSX文件或源调用时成功运行,但在从.NET应用程序调用时失败

1 个答案:

答案 0 :(得分:0)

我从这篇文章中找到了答案:

http://social.msdn.microsoft.com/Forums/sqlserver/en-US/03bae0fc-b51c-4258-a80a-8426e855576b/mixed-mode-assembly-and-uselegacyv2runtimeactivationpolicy?forum=sqlintegrationservices

问题是Visual Studio 2010中的某个库(ManagedDTS.dll)有问题,因此需要在项目的“App.config”中添加兼容性选项才能使某些功能正常工作。

<强>&LT; startup startup =“”useLegacyV2RuntimeActivationPolicy =“true”&gt;

<?xml version="1.0"?>
<configuration>
   <startup startup="" useLegacyV2RuntimeActivationPolicy="true">
   <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
</configuration>