sql – 从SSIS调用时删除语句失败

我正在尝试从SSIS中编排Snowflake.

我正在使用ODBC连接和执行SQL任务. truncate table语句工作正常,任务成功完成.将此更改为删除,任务失败,并显示以下错误:

failed with the following error: “Error HRESULT E_FAIL has been returned from a call to a COM component.”. Possible failure reasons: Problems with the query, “ResultSet” property not set correctly, parameters not set correctly, or connection not established correctly.

我可以从雪花查询历史中看到查询成功完成:

《sql – 从SSIS调用时删除语句失败》

我怀疑“结果”看起来像SSIS,因为它被设置为期望“无”.我已将此更改为单行和“完整结果集”到对象中,但无论设置如何都仍会出错.

为了让SSIS成功执行针对Snowflake的语句,我需要更改什么?

编辑:

添加我的删除声明:

delete from SUMMARY.Data_minutes
where date >= dateadd(day,-5  ,'2019-01-20' )
and date <= '2019-01-20' 

最佳答案 试图找出问题所在

在搜索此问题时,我在Devart support page发现了一些有趣的内容,其中报告了类似的问题:

According to Microsoft documentation if the query has not affected any records will return the result SQL_NO_DATA (for the ODBC 3.x specification). Our driver and SSIS use the ODBC 3.x specification, however, in the described case,SSIS implements the behavior as ODBC 2.x . That’s why, when the result of SQL_NO_DATA is received, the error “Error HRESULT E_FAIL has been returned from a call to a COM component” is returned.

基于Microsoft documentation

When an ODBC 3.x application calls SQLExecDirect, SQLExecute, or SQLParamData in an ODBC 2.x driver to execute a searched update or delete statement that does not affect any rows at the data source, the driver should return SQL_SUCCESS, not SQL_NO_DATA. When an ODBC 2.x or ODBC 3.x application working with an ODBC 3.x driver calls SQLExecDirect, SQLExecute, or SQLParamData with the same result, the ODBC 3.x driver should return SQL_NO_DATA.

这意味着当没有行匹配以下条件时,它将引发异常(在类似情况下:ODBC版本冲突):

where date >= dateadd(day,-5  ,'2019-01-20' )
and date <= '2019-01-20' 

要尝试的东西

我现在无法测试此变通方法,但您可以尝试两种方法:

>在delete命令后添加一个虚拟选择行

delete from SUMMARY.Data_minutes
where date >= dateadd(day,-5  ,'2019-01-20' )
and date <= '2019-01-20' 

select 1

>创建存储过程并将日期作为参数传递,并从执行SQL任务执行它(也尝试在存储过程结束时添加虚拟选择命令)

 Exec sp_Delete ?
点赞