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

Metaphor
  • 6,157
  • 10
  • 54
  • 77

2 Answers2

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.

billinkc
  • 59,250
  • 9
  • 102
  • 159
  • thanks, looking at it and not seeing it! I did notice the type discrepancy as I was writing this post and fixed it already. )) – Metaphor Dec 05 '13 at 21:54
  • 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. – codeMonkey May 03 '18 at 00:10
  • 2
    @codeMonkey Does *anything* work well with package parts – billinkc May 03 '18 at 02:35
1

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

long lngMaxRowsToPull = Convert.ToInt64(Dts.Variables["$Project::MaxRowsPerPull"].Value);
Karthikeyan VK
  • 5,310
  • 3
  • 37
  • 50
  • It would help if you added some descriptive text explaining what about your code solves the problem and why. Thanks! – cb4 Dec 08 '17 at 04:15