Dynamically modifying mail message - SSIS
Hi, I am using a send mail task with expression. The expression uses a variable for message source. This send mail task is called in case of any error (event handling). In case the script doesn't return a proper return code, I am modifying the value of variable to be sent as the message. Here is the script: If rc <> 0 Then Dts.TaskResult = ScriptResults.Failure Dts.Variables( "error_message").Value = "Snap task failed at Update VV " MsgBox(Dts.Variables( "error_message").Value) Return End If My problem is that I when the script fails, the value of the variable is not modified. It just takes the value which is declared in the package. Can anyone please suggest how to do this? Thanks Ayush
December 9th, 2010 1:05pm

Why Dts.TaskResult = ScriptResults.Failure is before Dts.Variables("error_message").Value = "Snap task failed at Update VV " ? How do you get the RC?Arthur My Blog
Free Windows Admin Tool Kit Click here and download it now
December 9th, 2010 1:12pm

I was not sure if they should be in a certain sequence. I am getting the RC using a shell output through the below functions: Dim Wshell = CreateObject("wscript.shell") rc = Wshell.Run(updatevv_cmd, 0, True) where updatevv_cmd is a command I am running. Thanks Ayush
December 9th, 2010 1:25pm

Is this value a non 0? Fail the task as the last step!Arthur My Blog
Free Windows Admin Tool Kit Click here and download it now
December 9th, 2010 1:28pm

Thanks Arthur I tried moving the failure below the error_message assignment line. The result is still the same. Yes I am currently testing it for a non zero value. Is this the case that the expression value for the message source is set at the start of the execution of the package, and takes the default value of "error_message" variable and can't be changed dynamically? Thanks Ayush
December 9th, 2010 1:34pm

Why not to use execute process task? You can refer to this article for more help: http://drkd.spaces.live.com/blog/cns!6510982E19F36FFF!297.entry?sa=168081090 Also: In the scenario above I do not understand why you fail the task, do you have Dts.TaskResult = Dts.Results.Success At all? Arthur My Blog
Free Windows Admin Tool Kit Click here and download it now
December 9th, 2010 1:44pm

Hi After the statement Dts.TaskResult = ScriptResults.Failure the control will raise onerror event it won't execute further statements so it is update the variable in onerror event other wise update the variable and ten make it fail task Dts.TaskResult = ScriptResults.Failure then it will work as you epected
December 10th, 2010 2:35am

Could you send us the entire script that you have. I would suggest you have the Dts.TaskResult = ScriptResults.Failure does the task go red on execution of the script? if not the condition you are checking is never met. Tweet me..
Free Windows Admin Tool Kit Click here and download it now
December 10th, 2010 3:55am

Hi Try this If rc <> 0 Then Dts.Variables( "error_message").Value = "Snap task failed at Update VV " MsgBox(Dts.Variables( "error_message").Value) Dts.TaskResult = ScriptResults.Failure End If
December 10th, 2010 5:24am

Well, its puzzling but the send mail task is working with the newly assigned value of "error_message" variable, if I put the send mail task in the control flow tab and not in Event Handler tabl. I also did put my dts.taskresult=scriptresults.failure as the last statement. So my understanding is that the value assigned in the control flow task doesn't pass to the value of the same variable in event handler. I did try the way "Somenothing" has suggested, but still the effect is the same if the send mail task is in the Event handler tab. Thanks all for help though. Ayush
Free Windows Admin Tool Kit Click here and download it now
December 10th, 2010 2:02pm

Just to step back a little, I would want to check the scope of the variable that you may have defined. In case they are package scoped, can we have a look at your package? Rakesh Parida | MSFT
December 10th, 2010 2:21pm

Just to step back a little, I would want to check the scope of the variable that you may have defined. In case they are package scoped, can we have a look at your package? Rakesh Parida | MSFT
Free Windows Admin Tool Kit Click here and download it now
December 10th, 2010 10:20pm

The scpe of the variable is package scope. Hence I assume that it should grab the value from control flow and pass it to event handler? Thanks Ayush
December 11th, 2010 4:21pm

Can you try this? 1. In case of error a. Modify your variable b. Call Dts.FireError with your error message 2. Avoid setting Dts.TaskResult to failure Let me know if it works. I would still like to have a look at your package.Rakesh Parida | MSFT
Free Windows Admin Tool Kit Click here and download it now
January 21st, 2011 9:31pm

Hi Rakesh, I am not finding a way to send my package as an attachment. Can you please let me know? Today I had a worse issue with these emails with my current setting. A cube processing task failed and generated 1000s of error messages. All these error messages were sent out in separate emails, which resulted in overload of the email exchange. I am not sure where I am wrong. Thanks Ayush
January 27th, 2011 12:00pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics