SSIS 包停止获取临时表的元数据
在 SSIS 包中,多个流创建全局临时表作为数据的暂存区域。然而,一个流在尝试为其临时表获取元数据时遇到间歇性故障。错误消息显示:
Unspecified error. The metadata could not be determined because statement 'select * from '##TmpMcsConfigurationDeviceHistory86B34BFD041A430E84CCACE78DA336A1'' uses a temp table.
临时表的创建表达式为:
CREATE TABLE " + @[User::TmpMcsConfigurationDeviceHistory] + " ([RecId] [bigint] NULL,[DataAreaID] [nvarchar](4) COLLATE database_default NULL,[Asset] [bigint] NULL,[Code] [nvarchar](255) COLLATE database_default NULL,[Configuration] [bigint],[StartdateTime] [datetime] NULL,[EndDateTime] [datetime] NULL)
求值,该表达式变为:
CREATE TABLE ##TmpMcsConfigurationDeviceHistory764E56F088DC475C9CC747CC82B9E388 ([RecId] [bigint] NULL,[DataAreaID] [nvarchar](4) COLLATE database_default NULL,[Asset] [bigint] NULL,[Code] [nvarchar](255) COLLATE database_default NULL,[Configuration] [bigint],[StartdateTime] [datetime] NULL,[EndDateTime] [datetime] NULL)
解决方案
要解决此问题,请考虑使用WITH RESULT SETS 显式定义临时表的元数据。这允许 SSIS 绕过 sp_describe_first_result_set 步骤并使用提供的元数据。
实现
对于存储过程,请使用以下语法:
EXEC ('dbo.MyStoredProcedure') WITH RESULT SETS ( ( MyIntegerColumn INT NOT NULL, MyTextColumn VARCHAR(50) NULL, MyOtherColumn BIT NULL ) )
对于简单的 SQL 查询,请使用以下语法:
EXEC (' CREATE TABLE #a ( MyIntegerColumn INT NOT NULL, MyTextColumn VARCHAR(50) NULL, MyOtherColumn BIT NULL ) INSERT INTO #a ( MyIntegerColumn, MyTextColumn, MyOtherColumn ) SELECT 1 AS MyIntegerColumn, ''x'' AS MyTextColumn, 0 AS MyOtherColumn SELECT MyIntegerColumn, MyTextColumn, MyOtherColumn FROM #a') WITH RESULT SETS ( ( MyIntegerColumn INT NOT NULL ,MyTextColumn VARCHAR(50) NULL ,MyOtherColumn BIT NULL ) )
以上是为什么我的 SSIS 包无法获取临时表的元数据,如何使用'WITH RESULT SETS”修复它?的详细内容。更多信息请关注PHP中文网其他相关文章!