首页 > 解决方案 > 如何在 SSIS 中的 OLE DB 源的存储过程执行中传递参数

问题描述

在 SSIS 的 OLE DB 源中执行存储过程时遇到问题,

我已将 OLE DB 源设置为 SQL 命令并输入以下内容:

在此处输入图像描述

这是 SQL 命令文本的代码:

exec timesheet_r12..TIME_lynx_extract ?,?,?,?,?,?,?,?,?,?,?,?,?

WITH RESULT SETS (
(
worker_reference    NVarchar(50),
placement_reference  NVarchar(10),
worker_name NVarchar(50),
job_title   NVarchar(100),
authorising_line_manager    NVarchar(100),
timesheet_date  datetime,
company_agent_name  NVarchar(100),
type_of_worker  NVarchar(100),
week_number NVarchar(100),
hours_worked    NVarchar(100),
rate_description    NVarchar(100),
rate_per_hour   NVarchar(10),
job NVarchar(100),
work_stage  NVarchar(100),
project_name    NVarchar(100),
location NVarchar(100)
)
)

我需要发送的前 2 个参数是 @startweek 和 @endweek,我需要了解如何将最后一个星期五发送为“@endweek”,将 4 周前的星期五发送为“@startweek”(前 4 个星期五)。

如果我想用硬编码的@startweek 和@endweek 执行数据库中的存储过程,我可以使用以下命令:

exec timesheet_r12..TIME_lynx_extract
     '19 Jul 2018', 
     '16 Aug 2019',
     null,null,null,null,null,null,null,null,null,null,null

这是我在 SSIS 中执行包时遇到的错误:

SSIS package "C:\Users\AGUIRRG2\source\repos\Integration Services Project3\Integration Services Project3\Package.dtsx" starting.
Information: 0x4004300A at Data Flow Task, SSIS.Pipeline: Validation phase is beginning.
Information: 0x4004300A at Data Flow Task, SSIS.Pipeline: Validation phase is beginning.
Information: 0x40043006 at Data Flow Task, SSIS.Pipeline: Prepare for Execute phase is beginning.
Information: 0x40043007 at Data Flow Task, SSIS.Pipeline: Pre-Execute phase is beginning.
Error: 0xC0207014 at Data Flow Task, OLE DB Source [49]: The SQL command requires a parameter named "@startweek", which is not found in the parameter mapping.
Error: 0xC004701A at Data Flow Task, SSIS.Pipeline: OLE DB Source failed the pre-execute phase and returned error code 0xC0207014.
Information: 0x40043008 at Data Flow Task, SSIS.Pipeline: Post Execute phase is beginning.
Information: 0x4004300B at Data Flow Task, SSIS.Pipeline: "Excel Destination" wrote 0 rows.
Information: 0x40043009 at Data Flow Task, SSIS.Pipeline: Cleanup phase is beginning.
Task failed: Data Flow Task
Warning: 0x80019002 at Package: SSIS Warning Code DTS_W_MAXIMUMERRORCOUNTREACHED.  The Execution method succeeded, but the number of errors raised (2) 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 "C:\Users\AGUIRRG2\source\repos\Integration Services Project3\Integration Services Project3\Package.dtsx" finished: Failure.
The program '[24756] DtsDebugHost.exe: DTS' has exited with code 0 (0x0).

所以现在我需要知道如何将参数传递给 SSIS,以及如何使它们动态化,@startweek并且@endweek可以计算。

谢谢你。

标签: sql-serverstored-proceduresssis

解决方案


我曾经在一个项目上遇到过同样的问题。我认为你需要为你的参数做一个特定的映射

您可以按照本文中提到的所有步骤操作:在 SSIS OLE DB 源代码编辑器中映射存储过程参数


推荐阅读