问题
I need to route an email using the Send Mail Task, in SSIS 2005 depending on a variable within a script task.
So, far, I've created a Variable in the variables tab, but can't seem to figure out where to set it, or how to access it using the code.
Apologies for the vague question, but this isn't my bag, and i'm trying to help out another team. I can send through more detail if required.


Public Function SetEmailAddress(ByVal variable x As String) As String
if x = y then set the isConfirmation variable.
The little code snippet above, is what i'm trying to achieve within the Script Task - process file object.
回答1:
I don't have a copy of the 2005 SSIS release handy, so some of this answer is approximate.
The big picture what you will need to do is modify the .Value
of an object in the SSIS
Variables collection.
Setting Variable's value via code
With 2008+, they modified the editor so you can specify that you're going to access SSIS Variables. I can't recall if they made that available in 2005. Based on Jamie's post, it looks like it was available. So, you can either use a GUI if it's available to indicate you want to modify the value of isConfirmation
or you can go through the lock/unlock process below
Imports Microsoft.SqlServer.Dts.Runtime
Public Class ScriptMain
Public Sub Main()
Dim vars As Variables
Dts.VariableDispenser.LockOneForWrite("isConfirmation", vars)
' Assign a boolean value to the thing we just locked for modifying
vars(0).Value = (x=y)
vars.Unlock()
Dts.TaskResult = Dts.Results.Success
End Sub
End Class
If you use the GUI to indicate you're locking the variable, it'd be approximately
Imports Microsoft.SqlServer.Dts.Runtime
Public Class ScriptMain
Public Sub Main()
' Update it in place
Dts.Variables("isConfirmation").Value = (x=y)
Dts.TaskResult = Dts.Results.Success
End Sub
End Class
Even though you're in VB which is not case sensitive, the base SSIS object model is case sensitive so IsConfirmation is not going to be found in the Variables collection.
Putting it all together
Assuming you have three SSIS Variables created, isConfirmation - boolean and two String variables Address1 and Address2. When isConfirmation is true, we wish to use Address1. When false, we want to use Address2.
You can create the expression directly on the object but you can't debug that. Instead, create another variable, FinalAddress of type string. Right click on it and in the properties menu, set the EvaluateAsExpression property to True and in the Expression use the following formula @[User::isConfirmation] ? @[User::Address1] : @[User::Address2]
Then, on the Send Mail Task itself, set the ToLine (approximate) to be @[User::FinalAddress]
Troubleshooting
According to the comments, there are problems when the package is run at the server. In cases like this, I'd look to raise some event messages from the package.
Dim fireAgain As Boolean = True
Dim isCurrent As Boolean = True
' logic here
' report on status of what we care about
Dts.Events.FireInformation(0, "Debug", String.Format("isCurrent = {0}", isCurrent), String.Empty, 0, ByRef fireAgain)
When you call the package, either through agent or the command line, you're going to want to make sure the /REPORTING E
parameter becomes /REPORTING EIW
(to report errors, warnings and information events. Rarely is it a bad practice to log this information as it is)
来源:https://stackoverflow.com/questions/23895347/ssis-package-2005-dynamic-toline