dirtyw0lf
dirtyw0lf

Reputation: 1958

Changing variable scope in SSIS programatically

Is there a way to change a variable scope in SSIS programatically?

for example, this variable will be created on the package level:

package.Variables.Add("sSourceObjectId", false, "User", 1);

But I need to create the variable on the OnError scope, because the system variable ErrorCode is not visible to the package level.

Upvotes: 1

Views: 765

Answers (1)

billinkc
billinkc

Reputation: 61201

You'd need to access the Variables collection on the specific Task/Container

The following code creates an SSIS package that has an OnError event handler at the package level. On that event handler, eh, I add the variable sSourceObjectId

string path = @"C:\ssisdata\p1.dtsx";

Application app = new Application();
Package pkg = new Package();
pkg.Name = "so_29925774";
DtsEventHandler eh = pkg.EventHandlers.Add("OnError") as DtsEventHandler;

eh.Variables.Add("sSourceObjectId", false, "User", 1);

app.SaveToXml(path, pkg, null);

Resulting package

You can see that the Variable is scoped to the OnError event and not the package itself.

enter image description here

Upvotes: 2

Related Questions