Access Catalog SSIS package variable from SSMS execution

Spunny 366 Reputation points
2022-12-20T22:54:11.047+00:00

Hi,
we have all our SSIS packages in catalog. I need to execute this package in stored procedure and get 1 of the package variable value which gets it's value after running webservice in script task.
I am trying to get that value. But not able to. Some say by raising an event, can get information. I know that there is sql task to input those values into table and get it from table. I am trying to avoid it.

This is what I tried:
Added variable to ssis package and set it's Raise Change Event property to true.
Then, in script task code:
public void Main()
{

     string packageName = Dts.Variables["System::PackageName"].Value.ToString();  
     string taskName = Dts.Variables["System::TaskName"].Value.ToString();  
     string subComponent = packageName + "." + taskName;  
     int informationCode = 1001;  
     bool fireAgain = true;  
     Dts.Variables["User::rs"].Value = "trying my best";  
     string msg = "variable rs:" + Dts.Variables["User::rs"].Value.ToString();             
     Dts.Events.FireInformation(informationCode, subComponent, msg, string.Empty, 0, ref fireAgain);   
     Dts.TaskResult = (int)ScriptResults.Success;  
 }  

Execute SSIS package from SSMS. We can't use dts.exe utility
Declare @execution_id bigint

EXEC [SSISDB].[catalog].[create_execution] @package_name=N'Package.dtsx', @execution_id=@execution_id OUTPUT, @display _name=N'folderName', @Shayna Webb _name=N'projectName', @use32bitruntime=False, @reference_id=Null

Select @execution_id

EXEC [SSISDB].[catalog].[start_execution] @execution_id

select * from SSISDB.CATALOG.EVENT_MESSAGES where operation_id = 45827 --@execution_id

I get message as 'Package:Value of variable [rs] is changed to .', but no value in that.
What am I doing wrong?

Please let me know.
Thank You

SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,702 questions
Developer technologies | Transact-SQL
{count} votes

1 answer

Sort by: Most helpful
  1. Yitzhak Khabinsky 26,586 Reputation points
    2022-12-22T16:40:24.347+00:00

    Hi @Spunny ,

    It is definitely possible.
    Andy Leonard shared two methods how to do it some years ago.

    Check it out here: ETL-instrumentation-logging-SSIS-variable-values


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.