Это расширение этого вопроса. Я установил пользовательскую переменную с именем Type и установил для нее тип данных Int16. В моей задаче «Сценарий», в зависимости от результатов проверки содержимого другой пользовательской переменной с именем fileName, я устанавливаю значение User::Type в одно из трех значений. Все эти значения являются целыми числами. Значение по умолчанию User::Type — 0, а 3 новых значения — 1, 2 и 3. Задача «Сценарий» — это первый элемент внутри контейнера цикла по каждому элементу в моем потоке управления. Код для задачи сценария:
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 на любой другой элемент, а также обновлю сценарий, чтобы назначить этот тип данных, я все равно получаю эту ошибку. Я удалил эту ссылку на переменную из задачи создания сценариев и удалил саму переменную из пакета, а затем снова добавил ее, но все равно получаю ту же ошибку.
Пока я не установил тип переменной String. Тогда это сработало. Есть ли какое-то другое преобразование типа данных, которое происходит за кулисами, но я не могу его увидеть?