简体   繁体   English

SSIS 错误:[执行 SQL 任务] 错误:执行查询

[英]SSIS error : [Execute SQL Task] Error: Executing the query

I am creating a SSIS package and trying to extract data by calling stored procedures from one database and inserting the result set values into another table of different database.我正在创建一个 SSIS 包并尝试通过从一个数据库调用存储过程并将结果集值插入到不同数据库的另一个表中来提取数据。 I have created a Execute SQL task to extract the data, a for each loop container to loop through the result set and Execute SQL task within the for loop container to insert the result set data into another database table.我创建了一个执行 SQL 任务来提取数据,一个 for each loop 容器循环遍历结果集,并在 for 循环容器中创建了一个 Execute SQL 任务,将结果集数据插入另一个数据库表。 I am getting an the following error while inserting the records.插入记录时出现以下错误。 I guess its the issue with the mapping.我想这是映射的问题。

[Execute SQL Task] Error: Executing the query "insert into EmployeeCount (companyId..." failed with the following error: "Parameter name is unrecognized.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly. [执行 SQL 任务] 错误:执行查询“insert into EmployeeCount (companyId...” failed with the following error:“Parameter name is unrecognized.”。可能的失败原因:查询有问题,“ResultSet”属性设置不正确, 参数设置不正确,或连接未正确建立。

Following the screenshot of the template design按照模板设计的截图

在此处输入图像描述

Following is the edit window of execute sql task which in inside the foreach container以下是foreach容器内执行sql任务的编辑窗口

在此处输入图像描述

The insert statement插入语句

insert into EmployeeCount (companyId,dataItemName,dataItemvalue,fiscalYear,fiscalQuarter,PeriodTypeId) values(companyId,dataItemName,dataItemvalue,fiscalYear,fiscalQuarter,PeriodTypeId)

You will have to set "Parameter Name" in chronological order.您必须按时间顺序设置“参数名称”。

 i.e companyID parameter must be 0, dataItemvalue to 1 ....PeriodTypeId to 5 

Sample :样本 : 在此处输入图像描述

In the 'Parameter Mapping' for Parameter Name, instead of '?'在参数名称的“参数映射”中,而不是“?” give the values in a 0 based index ie 0,1,2,... till the end.给出基于 0 的索引中的值,即 0,1,2,... 直到最后。

Simple Workaround简单的解决方法

You can achieve this without using parameters, you can use expressions:您可以在不使用参数的情况下实现这一点,您可以使用表达式:

  1. Double click on the Execute SQL Task , Go To Expressions.双击Execute SQL Task ,转到表达式。

  2. add the following expression to SqlStatementSource :将以下表达式添加到SqlStatementSource

     "insert into EmployeeCount (companyId,dataItemName,dataItemvalue,fiscalYear,fiscalQuarter,PeriodTypeId) values(" + (DT_WSTR,50)@[User::companyId] + ",'" + @[User::dataItemName] + "'," + (DT_WSTR,50)@[User::dataItemvalue] + "," + (DT_WSTR,50)@[User::fiscalYear] + "," + (DT_WSTR,50)@[User::fiscalQuarter] + "," + (DT_WSTR,50)@[User::PeriodTypeId] + ")"

Be aware!意识到! This approach makes your solution vulnerable to SQL injections这种方法使您的解决方案容易受到 SQL 注入的影响

As an option:作为一种选择:

You may be trying to insert too long values into shorter columns您可能试图将太长的值插入较短的列

For example if you create Source DB you need to be sure that each column have sufficient maximum length and you don't put largest values (too long values) into this column.例如,如果您创建 Source DB,则需要确保每列都有足够的最大长度,并且不要将最大值(太长的值)放入该列。

So unfortunately SSIS don't specify the problematic column, and you need to find it by yourself or enlarge maximum length of every column.所以不幸的是SSIS没有指定有问题的列,你需要自己找到它或者扩大每列的最大长度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM