Question

I have a SQL server stored procedure which takes as parameter a part of the database name. It works perfectly when executing from SQL Server Management Studio.

However I need to call this SP from SSIS OLE DB Source component. When I specify the SQL command and parameters in the OLE DB Source component, I get the following error:

"Error at SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005. An OLE DB record is available. Source: "Microsoft SQL Server Native Client 10.0" Hresult: 0x80004005 Description: "The OLE DB provider "SQLNCLI10" for linked server does not contain the table The table either does not exist or the current user does not have permissions on that table.".: Unable to retrieve column information from the data source. Make sure your target table in the database is available".

Basically it cant find the table used by the stored procedure as the database name is parameterized. I searched around and found that OLE DB data source needs meta data for the table. How can I provide this?

This is my stored procedure:

USE [ILLP]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


ALTER PROCEDURE [dbo].[OUTPUT_MI_Tyep12] @param1 varchar(5)
AS
BEGIN
    SET FMTONLY OFF;
   SET NOCOUNT ON;

declare @query varchar(1000)

set @query='
SELECT [M12]
      ,[T3Size]
      ,[SizeVCost]
      ,NULL as [DefaultTonnage]
      ,NULL as [IdleCost]
      ,NULL as [SuperLocoID]
      ,[IfAllowFleetSizeVio]
  FROM [ServN\PROD2].[Scenario_' + @param1 +'_PRD].[dbo].[Para_LTYPE]'

exec(@query)
END
Was it helpful?

Solution

I am guessing you are trying to loop through different databases using the SP with a parameter in SSIS. However you could do this with a Select Command From variable source:

  1. Create a new Variable - SELECT_OUTPUT_MI_Tyep12 for instance (String Type);
  2. Within the variable properties check EvaluateAsExpression = True;
  3. Under the Expression use the following:

    SELECT [M12]
          ,[T3Size]
          ,[SizeVCost]
          ,NULL as [DefaultTonnage]
          ,NULL as [IdleCost]
          ,NULL as [SuperLocoID]
          ,[IfAllowFleetSizeVio] 
    FROM [ServN\\PROD2].[Scenario_" + @[User::DBNameParameter]  + "_PRD].[dbo].[Para_LTYPE]
    
  4. Change the @[User::DBNameParameter] for your specific one;

  5. Use the SQL Command from variable in the connection manager, selecting the SELECT_OUTPUT_MI_Tyep12 variable.

This should allow you to gather all the Meta data back from the table and carry on with the rest of the data flow.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top