Domanda

I have created a SQL stored procedure that produces the expected results when I call it from SQL Management Studio, it has one output parameter which is a message that tells me where the proc failed, if it fails. Here is the top part of the proc

CREATE PROCEDURE [dbo].[uspProgramUpdate] 
    @EmailFailMessage VARCHAR(100) OUTPUT

At the bottom of my stored procedure is where I set the value of the variable:

BEGIN CATCH
    ROLLBACK TRAN [CoS1]
    RAISERROR ('***An error occurred during processing, all transactions have been rolled back.  Correct the error and restart this process.***', 16, 1)
    SET @EmailFailMessage = '***An error occurred during processing, all transactions have been rolled back.  Correct the error and restart this process.***'
END CATCH

What I am trying to do (that I can't figure out) is how to capture the text of EmailFailMessage so I can use that text in an email within SSIS.

I have created an Execute SQL Task in SSIS which executes the stored procedure successfully on the SQL server. I have successfully captured the RAISERROR event and I can see that in the output window within Visual Studio window when I run the SSIS package:

Error: 0xC002F210 at Execute SQL - run uspProgramUpdate, Execute SQL Task: Executing the query "EXEC uspProgramUpdate ?" failed with the following error: "***An error occurred during processing, all transactions have been rolled back.  Correct the error and restart this process.***". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
Task failed: Execute SQL - run uspProgramUpdate

The SQLStatement property of the SSIS task is:

EXEC uspCoSSleepProgramUpdate ? OUTPUT

I have the following SSIS variable:

User::EmailFailMessage (string), value = asdf

and the parameter is mapped on the SSIS SQL task in Parameter Mappings as follows:

Variable Name| Direction | Data Type | Parameter Name | Parameter Size
User::EmailFailMessage | Output | VARCHAR | @EmailFailMessage | -1

I have an email task that is being called and for that email task I have set:

MessageSource = @[User::EmailFailMessage]

When I run the SSIS package and receive the email, the message (body) of the email doesn't have the message from SQL after running the stored proc. It does have the initial value set for the User::EmailFailMessage variable and I am expecting that to change, but it isn't.

I have also tried, among other things, using 0 for the parameter name in the Parameter Mapping area of my Execute SQL Task. Using that doesn't change the result.

È stato utile?

Soluzione

Personally I use the error message variable that is available in the on Error event handler called User::dataFlowExceptionMessage. That will send the exact error message sent by the failing task. That would be what bubbled up from raiserror. BUt I would suggest that you use the real error message as part of your raise error mesaage to make it easier to daignose the reason why the rollback occurred. I want to know the exact error generally.

Another thing you can do is put your error into a table variable and then insert it into an exception table with the date and the proc name after the rollback. Table variables stay in scope thorugh a rollback. Then you could look in that table to pull the message for your email task and you also have a record of just exactly what failed and when and how often which is useful for troubleshooting.

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