Reading project parameters in Script Task
Asked Answered
S

2

18

This is what I'm trying to do in a script task:

long lngMaxRowsToPull = Convert.ToInt64(Dts.Variables["Project::MaxRowsPerPull"].Value);

I get an error message that the variable does not exist.

Yet Its defined as a ReadOnlyVariable to the script and it does exist as a project parameter.

Its defined as a ReadOnlyVariable to the script

And it does exist as a project parameter

Sharpeyed answered 5/12, 2013 at 21:42 Comment(0)
F
23

So close. ;)

Your code is trying to access a variable/parameter named Project::MaxRowsPerPull

In fact, the $ is significant so you need to reference $Project::MaxRowsPerPull

Also note that you have the data type for the parameter as Int32 but are then pushing it into Int64. You can always put a smaller type into a larger container but if you tried to fill the parameter with too large a value your package will asplode.

Footboy answered 5/12, 2013 at 21:44 Comment(3)
thanks, looking at it and not seeing it! I did notice the type discrepancy as I was writing this post and fixed it already. ))Sharpeyed
For what it's worth, this will work in Script Tasks, but not if they are inside Package Parts; in that case, create a variable name inside the Package Part, re-scope it to the Package once inside the Package, and then add this an expression @[$Project::MaxRowsPerPull] to the re-scoped variable.Mikvah
@Mikvah Does anything work well with package parts </sadtrombone>Footboy
T
2

You need to add $ to your parameter fetch name as per syntax.

long lngMaxRowsToPull = Convert.ToInt64(Dts.Variables["$Project::MaxRowsPerPull"].Value);
Tryma answered 8/12, 2017 at 3:51 Comment(1)
It would help if you added some descriptive text explaining what about your code solves the problem and why. Thanks!Belfry

© 2022 - 2025 — McMap. All rights reserved.