Domanda

About halfway through my SSIS package I have an Execute SQL task that calls a stored proc on the SQL server. That stored proc contains a transaction and updates certain records, there is no output of the stored proc. The transaction will roll back if an error is encountered during this stored proc.

What I can't figure out how to do is stop the processing of my SSIS package if the transaction in the stored proc encounters a problem and is rolled back.

What is going to be the best way to do this? I can add some logic to the stored proc to output success or failure but what I didn't see was how to use that in SSIS to stop processing.

È stato utile?

Soluzione

In your stored procedure, make sure you rollback the transaction and raise error when it happens. This way the task will fail and the ssis package will fail and stop executing.

    Begin Try
        Begin Tran deff
            Update [test].[dbo].[User2] 
            Set [Password]='abc'
            Where [User_ID]='abc'
        Commit Tran deff
    End Try

Begin Catch
IF XACT_STATE() <> 0 

  ROLLBACK TRANSACTION
  RAISERROR ('Transaction Rolled Back', 16, 1)

End Catch

Altri suggerimenti

Following Steps may help you.

  1. Create the output variable in Stored procedure which stores the success / failure message.
  2. Create the variable in SSIS to store the output from the Execute SQL task
  3. Configure the Execute SQL task to store the output parameter
  4. Drag the Script task into control flow
  5. Add the SSIS variable which you created in Step 2 as ReadOnlyVariables
  6. Click Edit Script
  7. Paste the following code in Public void Main() method

        //Change the variable name based on your SSIS package variable
        var sprocMessage = Dts.Variables["SprocOutout"].Value.ToString();
    
        if (sprocMessage=="failure")
        {
            Dts.Events.FireError(0, "SP failed", "SP failed and rolled back", string.Empty,0);
        }
    
        Dts.TaskResult = (int)ScriptResults.Success;
    

Hope it helps!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top