Click here to Skip to main content
15,881,631 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to get output parameter of a Stored procedure in SSIS Package using C#. I am able to save data if it is a new record. But I am not getting the output parameter value while executing the package.

Core Code:
Application app = new Application();

              //Package package = app.LoadPackage(@"E:\SSIS\SSIS_SP_Call_3\SSIS_SP_Call_3\Package1.dtsx", null);//Package Full Path(Configurable)

              Package package = app.LoadPackage(@"E:\SSIS\SSIS_SP_Call_3\SSIS_SP_Call_3\Package2.dtsx", null);//Package Full Path(Configurable)


              Variables vars = package.Variables;


              vars["Country"].Value = "India"; //Value of the Variable set in the Package
              vars["State"].Value = "Kerala1";//Value of the Variable set in the Package


              string Result = vars["Result"].Value.ToString();//Value of the Variable set in the Package




              Microsoft.SqlServer.Dts.Runtime.DTSExecResult results = package.Execute();//Excecute the SSIS Package (local_DtsError.Description.ToString())


What I have tried:

SP as below:
USE [testssis]
GO
/****** Object:  StoredProcedure [dbo].[InsertData]    Script Date: 04/11/2018 11:51:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--EXEC InsertData_Output @Country,@State,@Result 

--EXEC InsertData_Output 'India','Kerala','' 


ALTER PROCEDURE [dbo].[InsertData_Output]
(
      @Country    NVARCHAR(50)
    , @State      NVARCHAR(50)
                   
    ,@Result VARCHAR(1000) OUTPUT           
)
AS
BEGIN

declare @UserCount VARCHAR(40)

    SET NOCOUNT ON;
     
SELECT @UserCount = COUNT(*) FROM SSISUsingCS WHERE State = @State;

--SELECT @UserCount
 
IF(@UserCount > 0)
begin
 
 select  @Result = 'Record already exists';
 --select @Result
 
end
else
begin
    INSERT INTO dbo.SSISUsingCS (Country, State) VALUES(@Country, @State)
    Set  @Result = 'Record Saved Successfully';
    --select @Result
    
end
END



Code is as below:
private void CallSSIS_SP_SAVE_OUTPUT()
       {
           try
           {
               Application app = new Application();

               //Package package = app.LoadPackage(@"E:\SSIS\SSIS_SP_Call_3\SSIS_SP_Call_3\Package1.dtsx", null);//Package Full Path(Configurable)

               Package package = app.LoadPackage(@"E:\SSIS\SSIS_SP_Call_3\SSIS_SP_Call_3\Package2.dtsx", null);//Package Full Path(Configurable)


               Variables vars = package.Variables;


               vars["Country"].Value = "India"; //Value of the Variable set in the Package
               vars["State"].Value = "Kerala1";//Value of the Variable set in the Package


               string Result = vars["Result"].Value.ToString();//Value of the Variable set in the Package




               Microsoft.SqlServer.Dts.Runtime.DTSExecResult results = package.Execute();//Excecute the SSIS Package (local_DtsError.Description.ToString())



               if (results == Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure)
               {

                   foreach (Microsoft.SqlServer.Dts.Runtime.DtsError local_DtsError in package.Errors)
                   {



                       Console.WriteLine("Package Execution results: {0}", local_DtsError.Description.ToString());

                       Console.WriteLine();

                   }

               }

           }
           catch (Exception ex)
           {

           }

       }
Posted
Updated 11-Apr-18 1:43am

1 solution

You sure have a weird way of doing things.

Try moving this line to be AFTER the call to package.Execute()

C#
string Result = vars["Result"].Value.ToString();
 
Share this answer
 
Comments
ranio 11-Apr-18 10:04am    
The result is still coming as empty string value after package execution code
#realJSOP 11-Apr-18 10:12am    
Well then, the package isn't setting it, or the code you posted isn't reading it correctly. Make sure the package is setting it.
#realJSOP 11-Apr-18 10:28am    
This site might help:

https://docs.microsoft.com/en-us/sql/integration-services/run-manage-packages-programmatically/loading-the-output-of-a-local-package

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900