SSIS使用.CSV文件SQL Server 2005中的参数执行存储过程

cod*_*000 1 sql-server ssis sql-server-2005

我正在学习SSIS,这似乎是一件容易的事,但我被困住了.

我有一个包含此数据的CSV文件Orders.csv:

ProductId,Quantity,CustomerId
1,1,104
2,1,105
3,2,106
Run Code Online (Sandbox Code Playgroud)

我还有一个存储过程ssis_createorder作为输入参数:@productid int @quantity int @customerid int

我想要做的是创建一个SSIS包,它将.csv文件作为输入,并为.csv文件中的每一行调用ssis_createorder三次(第一行包含列名).

这是我到目前为止所做的.

我创建了一个SSIS包(Visual Studio 2005和SQL Server 2005).

在控制流程中,我有一个数据流任务.

数据流具有.csv文件的平面文件源.所有列都已映射.

我创建了一个名为Order类型的变量的变量.我还有变量CustomerId,ProductId和int32类型的数量.

接下来,我有一个Recordset Destination,它将.csv文件的内容分配给varialbe订单.我不确定如何使用这个工具.我将VariableName(在Customer Properties下)设置为User :: orders.我认为现在订单包含一个由原始.csv文件中的内容组成的ADO记录集.

接下来,我在Control Flow标记上添加一个ForEach循环容器,并将其链接到数据流任务.

在ForEach循环容器内部我将Enumerator设置为"ForEach ADO Enumerator".我正在将"ADO对象源变量"设置为User :: orders".对于Enumeration模式,我选择"第一个表中的行".

在变量映射选项卡中,我有User :: ProductId索引0,User :: Quantity索引1,User :: CustomerId索引2.我不确定这是否正确.

接下来,我在ForEach循环容器中有一个脚本任务.

我将ReadOnlyVariables设置为ProductId.

在Main方法中,这就是我正在做的事情:

 Dim sProductId As String = Dts.Variables("ProductId").Value.ToString

 MsgBox("sProductId")
Run Code Online (Sandbox Code Playgroud)

当我运行包时,我的ForEach循环容器变为亮红色,我收到以下错误消息

Error: 0xC001F009 at MasterTest: The type of the value being assigned to variable "User::ProductId" 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 1 to variable "User::ProductId" cannot be applied.
Error: 0xC001F009 at MasterTest: The type of the value being assigned to variable "User::Quantity" 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::Quantity" cannot be applied.
Error: 0xC001F009 at MasterTest: The type of the value being assigned to variable "User::CustomerId" 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 3 to variable "User::CustomerId" cannot be applied.
Warning: 0x80019002 at MasterTest: SSIS Warning Code DTS_W_MAXIMUMERRORCOUNTREACHED.  The Execution method succeeded, but the number of errors raised (12) 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 "Package.dtsx" finished: Failure.
     Dts.TaskResult = Dts.Results.Success
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激

cod*_*000 6

我的一位同事给我答案.

您不需要ForEach循环容器或RecordSet容器.

您只需要平面文件源和OLE DB命令.连接到您的数据库并在OLE DB Command内部选择适当的连接.

在"组件属性"中,输入以下SQLCommand:

exec ssis_createorder ?, ?, ? 
Run Code Online (Sandbox Code Playgroud)

"?" 是参数的占位符.

"列映射"选项卡下的"下一步"将.csv文件列映射到存储过程参数.

你已经完成并继续运行包.

谢谢Gary如果你在StackOverFlow我会给你一个upvote并接受你的答案.