我有一个在SQL Management Studio中运行良好的存储过程,但我在SSIS 2008 R2中运行它时遇到问题。如果我以Execute SQL Task
运行它,它运行正常没有任何错误,但当我在数据流任务中将它用作ADO NET源时,我收到错误消息
无效的对象名称#Results(Microsoft SQL Server,错误:208)
然而,当我点击预览时,我确实显示了一行数据。
我没有修改存储过程的访问权限,因此我不确定存储过程本身内部发生了什么,但正如我之前所说,我可以在管理工作室中运行存储过程SSIS中的执行SQL任务。
答案 0 :(得分:2)
SSIS中的一个步骤是验证元数据 - 合同说我们应该有一个整数,然后是字符大小8.当数据流数据库源组件(ado或ole)尝试获取其元数据时,它基本上是boils向下找到的第一个查询。
这里的方法与我们在存储过程中使用动态表的方法相同。更改您指定无法执行的存储过程,以便在预期的元数据上提供SSIS提示。
CREATE PROCEDURE dbo.Sample
AS
BEGIN
SET NOCOUNT ON;
-- Any condition that will never evaluate to true
IF NULL = NULL
BEGIN
-- SSIS will key off of this query even
-- though it is impossible for this branch to ever execute
-- So, define our metadata here
SELECT
CAST(NULL AS int) AS MyFirstColumn
, CAST(NULL as char(8)) AS SomeCodeColumn;
END
-- Assume complex queries here that banjax the metadata
-- yet ultimately return the actual data
SELECT TOP 1000
CAST(ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) AS int) AS MyFirstColumn
, CAST(LEFT(AC.name, 8) AS char(8)) AS SomeCodeColumn
INTO
#RubeG
FROM
sys.all_columns AS AC;
SELECT
RG.MyFirstColumn
, RG.SomeCodeColumn
FROM
#RubeG AS RG;
END
对于SQL Server 2012+的源,您可以尝试为EXECUTE调用指定WITH RESULT SETS
属性。
EXECUTE dbo.Sample
WITH RESULT SETS
(
(
c1 bigint
, c2 varchar(8)
)
);
示例biml包定义。
DFT Sample Result Set
此处代码
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<Connections>
<Connection
Name="tempdb"
ConnectionString="Data Source=.\dev2014;Initial Catalog=tempdb;Provider=SQLNCLI10.1;Integrated Security=SSPI;"
/>
<AdoNetConnection
Name="CM_ADO"
ConnectionString="Data Source=localhost\dev2014;Integrated Security=SSPI;Connect Timeout=30;Database=tempdb;"
Provider="SQL"
/>
</Connections>
<Packages>
<Package Name="so_31206473">
<Tasks>
<Dataflow Name="DFT Sample">
<Transformations>
<OleDbSource ConnectionName="tempdb" Name="OLESRC dbo_Source">
<DirectInput>EXECUTE dbo.Sample</DirectInput>
</OleDbSource>
<DerivedColumns Name="DER Placeholder" />
</Transformations>
</Dataflow>
<Dataflow Name="DFT Sample RESULTS SET">
<Transformations>
<OleDbSource ConnectionName="tempdb" Name="OLESRC dbo_Source RS">
<DirectInput>
<![CDATA[EXECUTE dbo.Sample
WITH RESULT SETS
(
(
c1 bigint
, c2 varchar(8)
)
);]]>
</DirectInput>
</OleDbSource>
<DerivedColumns Name="DER Placeholder" />
</Transformations>
</Dataflow>
<Dataflow Name="DFT SampleADO">
<Transformations>
<AdoNetSource ConnectionName="CM_ADO" Name="ADOSRC dbo_Sample">
<DirectInput>EXECUTE dbo.Sample</DirectInput>
</AdoNetSource>
<DerivedColumns Name="DER Placeholder" />
</Transformations>
</Dataflow>
<Dataflow Name="DFT SampleADO RESULTS SET">
<Transformations>
<AdoNetSource ConnectionName="CM_ADO" Name="ADOSRC dbo_Sample">
<DirectInput>
<![CDATA[EXECUTE dbo.Sample
WITH RESULT SETS
(
(
c1 bigint
, c2 varchar(8)
)
);]]>
</DirectInput>
</AdoNetSource>
<DerivedColumns Name="DER Placeholder" />
</Transformations>
</Dataflow>
</Tasks>
</Package>
</Packages>
</Biml>
OLE源的示例元数据
WITH RESULTS设置OLE源的元数据
ADO.NET提供商的结果是一样的,我在构建截图时没有注意到问题的细微差别。更新后的Biml使得添加它们变得微不足道。