Researching SSIS is a bit of a nightmare, there doesn't appear to be a 'modern' full set of tutorials.
After my question* a couple of days ago regarding how to pass variables from C# to SSIS Package Parameter and then into a script task, I then needed to pass an C# variable to SSIS Package Parameter and then into a Stored procedure within a reasonably complex data flow.
After reading around and then a fair bit of testing here is a discussion rather than a posting a question.
So here's how to do it:
1)Create a blank SSIS solution. Drag/drop a 'DataFlow Task' onto the 'Control flow'
Add an OLE DB Connection manager to your database server and database (not covered here). Use SQL Server Authentication. You may need to add a user and password to the server 'Securables'(not covered here).
2)Follow the solution from my previous post* and setup a Parameter. In my case Name=StoredProcedureParameter, data Type= string, Value= blank, False, False, empty.
3) Drag and drop 'OLE DB Source' and a 'Sort' into the Data Flow. Connect the OLED DEB SOurce output to the Sort Input.
The original package used an ADO.NET source but I couldn't find a way of referencing Parameters so I followed the suggestion from various forum posts to use 'OLE DB Source'.
4) Right Click the connection arrow and 'Enable Data Viewer'
This will allow you to view the returned data.
5) Double click the OLE DB Source
Select the OLDE DB Connection manager to your server and database. Data access mode = SQL Command.
SQL Command test = Exec StoredProcedureName @StoredProcedureParameter =?
Click Parameters Parameters = @StoredProcedureParameter, Variables = $Package::StoredProcedureParameter, Param Direction = Input
Preview will not work. do not worry.
6) Run the SSIS package in debug. If you have errors then Look at the 'Execution Results'. Maybe run 'SQL Profiler' (a MS SQLSERVER utility)
With any luck the dataviewer will return some data.
7) If in doubt add something at the top of your stored procedures that makes is a bit fault tolerant.
Something like this:
ALTER PROCEDURE [dbo].[StoredProcedureName] @StoredProcedureVariable varchar(60)
AS BEGIN
DECLARE @QueryDateYesterday date set @QueryDateYesterday = DATEADD(DAY,-1,GetDate())
if @StoredProcedureVariable is null or @StoredProcedureVariable = '' or @StoredProcedureVariable ='none'
BEGIN
SET @StoredProcedureVariable = CONVERT(char(10), @QueryDateYesterday,126) -- e.g. '2016-01-06'
END
*https://social.msdn.microsoft.com/Forums/sqlserver/en-US/936bf32a-b4ad-40f3-868e-216f03fb8118/c-direct-call-to-slq-server-2014-ssis-dtsx-package-script-task-cant-pass-parameters?forum=sqlintegrationservices