นี่เป็นส่วนขยายของคำถามนี้ ฉันได้ตั้งค่าตัวแปร User ชื่อ Type และตั้งค่าประเภทข้อมูลเป็น Int16 ในงานการเขียนสคริปต์ของฉัน ขึ้นอยู่กับผลลัพธ์ของการทดสอบเนื้อหาของตัวแปร User อื่นที่เรียกว่า fileName ฉันกำลังตั้งค่า User::Type ให้เป็นหนึ่งใน 3 ค่า ค่าเหล่านี้ทั้งหมดเป็นจำนวนเต็ม ค่าเริ่มต้นของ User::Type คือ 0 และค่าใหม่ 3 ค่าคือ 1, 2 และ 3 งานสคริปต์เป็นองค์ประกอบแรกภายใน Foreach Loop Container ใน Control Flow ของฉัน รหัสสำหรับงานสคริปต์:
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 แล้วมันได้ผล มีการแปลงประเภทข้อมูลอื่นๆ ที่เกิดขึ้นเบื้องหลังซึ่งฉันไม่สามารถมองเห็นได้หรือไม่