dbTalk Databases Forums  

variables in Script task versus Script Component?

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss variables in Script task versus Script Component? in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
artzoop@hotmail.com
 
Posts: n/a

Default variables in Script task versus Script Component? - 10-03-2006 , 04:20 PM






Hi,

How do I reference and modify package scope variables in a script
component (within a data flow task)? I tried copying the syntax I used
in a Script task, but got a "Dts" not declared:

Dts.Variables("User::myErrCount").Value = ...

Above works in Control flow Script task, but not within a Data Flow
Script component.

I'm simply trying to increment an error count variable.

Thank you,

Greg


Reply With Quote
  #2  
Old   
Charles Kangai
 
Posts: n/a

Default RE: variables in Script task versus Script Component? - 10-04-2006 , 04:35 AM






Use the following:

Me.Variables.myErrCount

Charles Kangai, MCT, MCDBA
Author of Learning Tree's 4-day course: "SQL Server 2005 Integration
Services" http://www.learningtree.com/courses/134.htm
Author of Learning Tree's 4-day course: "SQL Server Reporting Services"
http://www.learningtree.com/courses/523.htm
email: charles at kangai.demon.co.uk



"artzoop (AT) hotmail (DOT) com" wrote:

Quote:
Hi,

How do I reference and modify package scope variables in a script
component (within a data flow task)? I tried copying the syntax I used
in a Script task, but got a "Dts" not declared:

Dts.Variables("User::myErrCount").Value = ...

Above works in Control flow Script task, but not within a Data Flow
Script component.

I'm simply trying to increment an error count variable.

Thank you,

Greg



Reply With Quote
  #3  
Old   
artzoop@hotmail.com
 
Posts: n/a

Default Re: variables in Script task versus Script Component? - 10-04-2006 , 08:26 AM



Thanks, Charles,

Your posting helped, but as I am a novice, it is taking me an hour
already searching for the correct syntax to increment that
"Me.Variable".

Dim countit As Integer = CType(Me.Variables.errDealerNAcount, Integer)
countit = countit + 1
Me.Variables.errDealerNAcount = countit

Can you advise the correct coding for incrementing that variable?

Thank you,
Greg

Charles Kangai wrote:
Quote:
Use the following:

Me.Variables.myErrCount

Charles Kangai, MCT, MCDBA
Author of Learning Tree's 4-day course: "SQL Server 2005 Integration
Services" http://www.learningtree.com/courses/134.htm
Author of Learning Tree's 4-day course: "SQL Server Reporting Services"
http://www.learningtree.com/courses/523.htm
email: charles at kangai.demon.co.uk



"artzoop (AT) hotmail (DOT) com" wrote:

Hi,

How do I reference and modify package scope variables in a script
component (within a data flow task)? I tried copying the syntax I used
in a Script task, but got a "Dts" not declared:

Dts.Variables("User::myErrCount").Value = ...

Above works in Control flow Script task, but not within a Data Flow
Script component.

I'm simply trying to increment an error count variable.

Thank you,

Greg




Reply With Quote
  #4  
Old   
Charles Kangai
 
Posts: n/a

Default Re: variables in Script task versus Script Component? - 10-04-2006 , 09:41 AM



Hi Greg,

Here is what you need to do:

1) Reference your errDealerNAcount variable in the ReadWriteVariables
property of your Script component properties. I think you have already done
this.
2) In your code, change the declaration of your countit variable to (declare
the variable at class level, outside of any procedures):

Dim countit as Integer = 0

You are not allowed to reference the errDealerNAcount at this point as you
are going to change it.

3) Write your code to increment countit inside the row by row processing
procedure, but again do NOT reference the variable errDealerNAcount:

countit = countit + 1

4) Create a PostExecute procedure within your Script class and change the
value of the variable to the final value of countit here:

Public Overrides Sub PostExecute()
Me.Variables.errDealerNAcount = countit
End Sub

The main point is that you are ONLY allowed to reference a variable you are
going to change in the PostExecute event, not anywhere else. There is another
method of doing it where you lock the variable yourself using the
VariableDispenser, but this is the simpler method.

Let me know whether you get it to work.

Cheers

Charles Kangai, MCT, MCDBA
Author of Learning Tree's 4-day course: "SQL Server 2005 Integration
Services" http://www.learningtree.com/courses/134.htm
Author of Learning Tree's 4-day course: "SQL Server Reporting Services"
http://www.learningtree.com/courses/523.htm
email: charles at kangai.demon.co.uk





"artzoop (AT) hotmail (DOT) com" wrote:

Quote:
Thanks, Charles,

Your posting helped, but as I am a novice, it is taking me an hour
already searching for the correct syntax to increment that
"Me.Variable".

Dim countit As Integer = CType(Me.Variables.errDealerNAcount, Integer)
countit = countit + 1
Me.Variables.errDealerNAcount = countit

Can you advise the correct coding for incrementing that variable?

Thank you,
Greg

Charles Kangai wrote:
Use the following:

Me.Variables.myErrCount

Charles Kangai, MCT, MCDBA
Author of Learning Tree's 4-day course: "SQL Server 2005 Integration
Services" http://www.learningtree.com/courses/134.htm
Author of Learning Tree's 4-day course: "SQL Server Reporting Services"
http://www.learningtree.com/courses/523.htm
email: charles at kangai.demon.co.uk



"artzoop (AT) hotmail (DOT) com" wrote:

Hi,

How do I reference and modify package scope variables in a script
component (within a data flow task)? I tried copying the syntax I used
in a Script task, but got a "Dts" not declared:

Dts.Variables("User::myErrCount").Value = ...

Above works in Control flow Script task, but not within a Data Flow
Script component.

I'm simply trying to increment an error count variable.

Thank you,

Greg





Reply With Quote
  #5  
Old   
artzoop@hotmail.com
 
Posts: n/a

Default Re: variables in Script task versus Script Component? - 10-04-2006 , 11:06 AM



Thanks, Charles, . . . getting closer ... however, my Script component
is within a data task that is within a Foreach ADO recordset, so the
countit reverts to 0 for each pass. Aside from that, when I added the
PostExecute sub within that Script, it errors because the countit
variable (from the other sub) is not declared.

Surely, there must be an easier way to increment a package level
variable within a Data task within a Foreach ADO loop?

Thank you. I appreciate your help with this.

Greg

Charles Kangai wrote:
Quote:
Hi Greg,

Here is what you need to do:

1) Reference your errDealerNAcount variable in the ReadWriteVariables
property of your Script component properties. I think you have already done
this.
2) In your code, change the declaration of your countit variable to (declare
the variable at class level, outside of any procedures):

Dim countit as Integer = 0

You are not allowed to reference the errDealerNAcount at this point as you
are going to change it.

3) Write your code to increment countit inside the row by row processing
procedure, but again do NOT reference the variable errDealerNAcount:

countit = countit + 1

4) Create a PostExecute procedure within your Script class and change the
value of the variable to the final value of countit here:

Public Overrides Sub PostExecute()
Me.Variables.errDealerNAcount = countit
End Sub

The main point is that you are ONLY allowed to reference a variable you are
going to change in the PostExecute event, not anywhere else. There is another
method of doing it where you lock the variable yourself using the
VariableDispenser, but this is the simpler method.

Let me know whether you get it to work.

Cheers

Charles Kangai, MCT, MCDBA
Author of Learning Tree's 4-day course: "SQL Server 2005 Integration
Services" http://www.learningtree.com/courses/134.htm
Author of Learning Tree's 4-day course: "SQL Server Reporting Services"
http://www.learningtree.com/courses/523.htm
email: charles at kangai.demon.co.uk





"artzoop (AT) hotmail (DOT) com" wrote:

Thanks, Charles,

Your posting helped, but as I am a novice, it is taking me an hour
already searching for the correct syntax to increment that
"Me.Variable".

Dim countit As Integer = CType(Me.Variables.errDealerNAcount, Integer)
countit = countit + 1
Me.Variables.errDealerNAcount = countit

Can you advise the correct coding for incrementing that variable?

Thank you,
Greg

Charles Kangai wrote:
Use the following:

Me.Variables.myErrCount

Charles Kangai, MCT, MCDBA
Author of Learning Tree's 4-day course: "SQL Server 2005 Integration
Services" http://www.learningtree.com/courses/134.htm
Author of Learning Tree's 4-day course: "SQL Server Reporting Services"
http://www.learningtree.com/courses/523.htm
email: charles at kangai.demon.co.uk



"artzoop (AT) hotmail (DOT) com" wrote:

Hi,

How do I reference and modify package scope variables in a script
component (within a data flow task)? I tried copying the syntax I used
in a Script task, but got a "Dts" not declared:

Dts.Variables("User::myErrCount").Value = ...

Above works in Control flow Script task, but not within a Data Flow
Script component.

I'm simply trying to increment an error count variable.

Thank you,

Greg






Reply With Quote
  #6  
Old   
Charles Kangai
 
Posts: n/a

Default Re: variables in Script task versus Script Component? - 10-04-2006 , 11:21 AM



As I mentioned in the previous post, you declare countit outside of both
procedures, just below your class declaration. It definitely works. It will
only zero after the Data Flow task is complete. If the Data Flow task is in a
loop, you can replace what I gave with you with:

Me.Variables.errDealerNAcount = Me.Variables.errDealerNAcount + countit

But this line of code is in the PostExecute sub. You should get it to work
in the next 5 minutes - good luck!


Charles Kangai, MCT, MCDBA
Author of Learning Tree's 4-day course: "SQL Server 2005 Integration
Services" http://www.learningtree.com/courses/134.htm
Author of Learning Tree's 4-day course: "SQL Server Reporting Services"
http://www.learningtree.com/courses/523.htm
email: charles at kangai.demon.co.uk



"artzoop (AT) hotmail (DOT) com" wrote:

Quote:
Thanks, Charles, . . . getting closer ... however, my Script component
is within a data task that is within a Foreach ADO recordset, so the
countit reverts to 0 for each pass. Aside from that, when I added the
PostExecute sub within that Script, it errors because the countit
variable (from the other sub) is not declared.

Surely, there must be an easier way to increment a package level
variable within a Data task within a Foreach ADO loop?

Thank you. I appreciate your help with this.

Greg

Charles Kangai wrote:
Hi Greg,

Here is what you need to do:

1) Reference your errDealerNAcount variable in the ReadWriteVariables
property of your Script component properties. I think you have already done
this.
2) In your code, change the declaration of your countit variable to (declare
the variable at class level, outside of any procedures):

Dim countit as Integer = 0

You are not allowed to reference the errDealerNAcount at this point as you
are going to change it.

3) Write your code to increment countit inside the row by row processing
procedure, but again do NOT reference the variable errDealerNAcount:

countit = countit + 1

4) Create a PostExecute procedure within your Script class and change the
value of the variable to the final value of countit here:

Public Overrides Sub PostExecute()
Me.Variables.errDealerNAcount = countit
End Sub

The main point is that you are ONLY allowed to reference a variable you are
going to change in the PostExecute event, not anywhere else. There is another
method of doing it where you lock the variable yourself using the
VariableDispenser, but this is the simpler method.

Let me know whether you get it to work.

Cheers

Charles Kangai, MCT, MCDBA
Author of Learning Tree's 4-day course: "SQL Server 2005 Integration
Services" http://www.learningtree.com/courses/134.htm
Author of Learning Tree's 4-day course: "SQL Server Reporting Services"
http://www.learningtree.com/courses/523.htm
email: charles at kangai.demon.co.uk





"artzoop (AT) hotmail (DOT) com" wrote:

Thanks, Charles,

Your posting helped, but as I am a novice, it is taking me an hour
already searching for the correct syntax to increment that
"Me.Variable".

Dim countit As Integer = CType(Me.Variables.errDealerNAcount, Integer)
countit = countit + 1
Me.Variables.errDealerNAcount = countit

Can you advise the correct coding for incrementing that variable?

Thank you,
Greg

Charles Kangai wrote:
Use the following:

Me.Variables.myErrCount

Charles Kangai, MCT, MCDBA
Author of Learning Tree's 4-day course: "SQL Server 2005 Integration
Services" http://www.learningtree.com/courses/134.htm
Author of Learning Tree's 4-day course: "SQL Server Reporting Services"
http://www.learningtree.com/courses/523.htm
email: charles at kangai.demon.co.uk



"artzoop (AT) hotmail (DOT) com" wrote:

Hi,

How do I reference and modify package scope variables in a script
component (within a data flow task)? I tried copying the syntax I used
in a Script task, but got a "Dts" not declared:

Dts.Variables("User::myErrCount").Value = ...

Above works in Control flow Script task, but not within a Data Flow
Script component.

I'm simply trying to increment an error count variable.

Thank you,

Greg







Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.