奇怪的问题设置用户变量数据类型用于脚本任务

时间:2011-02-25 13:50:47

标签: ssis

这是this问题的扩展。 我已经设置了一个名为“Type”的User变量,并将其数据类型设置为Int16。 在我的脚本任务中,根据另一个名为“fileName”的用户变量的内容测试结果,我将User :: Type的值设置为3个值中的一个。所有这些值都是整数。 User :: Type的默认值为0,3个新值为1,2和3。 脚本任务是我的控制流中Foreach循环容器内的第一个元素。 脚本任务的代码:

Imports System
Imports System.Data
Imports System.Math
Imports System.IO
Imports Microsoft.SqlServer.Dts.Runtime

Public Class ScriptMain
    ' Created: Zack Bethem – AmberLeaf
    Public Sub Main()
        Dim fileName As String
        Dts.Variables.Item("User::Type").Value = 0
        If Dts.Variables.Contains("User::fileName") = True Then
            fileName = CStr(Dts.Variables.Item("User::fileName").Value)
            'System.Windows.Forms.MessageBox.Show(fileName)
            If fileName.Contains("0074000") = True Then
                Dts.Variables.Item("User::Type").Value = 1
            ElseIf fileName.Contains("0072000") = True Then
                Dts.Variables.Item("User::Type").Value = 2
            ElseIf fileName.Contains("0022000") = True Then
                Dts.Variables.Item("User::Type").Value = 3
            End If
            Dts.TaskResult = Dts.Results.Success
        Else
            Dts.TaskResult = Dts.Results.Failure
        End If
    End Sub
End Class

我得到的错误是:

SSIS package "ACS_ALL_Import .dtsx" starting.
Error: 0xC001F009 at ACS_ALL_Import: The type of the value being assigned to variable "User::Type" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.
Error: 0xC001C012 at Foreach Loop Container: ForEach Variable Mapping number 2 to variable "User::Type" cannot be applied.
Warning: 0x80019002 at ACS_ALL_Import: SSIS Warning Code DTS_W_MAXIMUMERRORCOUNTREACHED.  The Execution method succeeded, but the number of errors raised (4) reached the maximum allowed (1); resulting in failure. This occurs when the number of errors reaches the number specified in MaximumErrorCount. Change the MaximumErrorCount or fix the errors.
SSIS package "ACS_ALL_Import .dtsx" finished: Failure.

如果我将User :: Type的数据类型更改为任何其他项目,并且还更新脚本以分配该类型的数据类型,我仍然会收到此错误。 我已从Scripting Task中删除了此变量引用,并从包中删除了变量本身,然后重新添加它,但我仍然遇到同样的错误。

直到我将变量类型设置为String。然后它奏效了。 是否存在我无法看到的幕后发生的某种其他数据类型转换?

3 个答案:

答案 0 :(得分:1)

刚刚在上一个问题上看到了您对此的评论。错误中的这一行:

Foreach Loop Container: ForEach Variable Mapping number 2 to variable "User::Type" cannot be applied.

向我表明问题可能不在于您的脚本任务,而在于每个循环容器中的变量映射。您是否在该任务中将Type变量设置为字符串,可能是错误的?

enter image description here

答案 1 :(得分:0)

我有类似的情况。只需将另一个变量定义为'for each loop'的文件名,您就不需要在脚本中使用'filename'。将另一个int32的包变量定义为'count',以便在脚本中使用。这有效!

答案 2 :(得分:0)

同样的问题,我的错误是我按照Grapefruitmoon的建议在Foreach循环中映射了太多列。我在查询中也有错误的列数,因此我将错误的列名映射到了我用于文件名的变量。一旦我在映射中更改了列号并删除了不需要的变量。该软件包有效。