home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.databases.ms-sqlserver      Notorious Rube Goldberg contraption      19,505 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 18,099 of 19,505   
   tshad to tshad   
   Re: SSIS - Passing User Variables to scr   
   24 Jan 11 18:09:30   
   
   From: tfs@dslextreme.com   
      
   I find that I can access the ReadOnlyVariable fine in a Script Task in the   
   Control Flow but cannot access ReadOnlyVariables from a Script Component in   
   the Data Flow.   
      
   I also cannot put breakpoints in the Script Component. But it works fine in   
   the script task.   
      
   Tom   
      
   "tshad"  wrote in message   
   news:K0p%o.1492$gx6.575@newsfe22.iad...   
   >I found that this error happens only when I put a variable in the   
   >ReadOnlyVariable property.  If I put the variable into the ReadWrite   
   >Variable I don't get that error.  Not sure why this is as I am not writing   
   >to the variable.   
   >   
   > I did find that I can't use the variable in my script actually.  When it   
   > runs and gets to the point where I accessed the variable I get the error:   
   >   
   > The collection of variables locked for read and write access is not   
   > available outside of PostExecute.   
   >   
   > Actually, I seem to be able to use it in PreExecute as well but not in the   
   > CreateNewOutputRows method.   
   >   
   > I am setting a variable in the PostExecute and PreExecute methods but it   
   > doesn't seem to do anything and leaves the original value that I initially   
   > set it to.   
   >   
   > My code looks like:   
   >   
   > *********************************   
   > using System;   
   > using System.Data;   
   > using Microsoft.SqlServer.Dts.Pipeline.Wrapper;   
   > using Microsoft.SqlServer.Dts.Runtime.Wrapper;   
   >   
   > [Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]   
   > public class ScriptMain : UserComponent   
   > {   
   >    string myIntegerVariableValue = "201123";          //Set it here   
   >   
   >    public override void PreExecute()   
   >    {   
   >        base.PreExecute();   
   >    }   
   >    public override void PostExecute()   
   >    {   
   >        base.PostExecute();   
   >        myIntegerVariableValue = Convert.ToString(Variables.RowCnt);   
   > //Set here   
   >    }   
   >    public override void Input0_ProcessInputRow(Input0Buffer Row)   
   >    {   
   >        myIntegerVariableValue = Convert.ToString(Variables.RowCnt);   
   > //Set it here   
   >    }   
   >    public override void CreateNewOutputRows()   
   >    {   
   >        Output0Buffer.AddRow();   
   >        myIntegerVariableValue = Convert.ToString(Variables.RowCnt);   //   
   > Causes error here   
   >   
   > // if left out it works fine but returns 201123   
   >        Output0Buffer.Resultstext = "This is a test with row count = " +   
   > myIntegerVariableValue;   
   >    }   
   > }   
   > ***********************************   
   >   
   > So how do I get the value from this variable????   
   >   
   > Thanks,   
   >   
   > Tom   
   > "tshad"  wrote in message   
   > news:MCm%o.1307$zw7.413@newsfe12.iad...   
   >> Not really.   
   >>   
   >> In my example, the script works as long as I don't include a   
   >> ReadOnlyVariable in the Scripts Property section.  If I add one in then I   
   >> get the error without changing anything else.   
   >>   
   >> And it is not like I misspelled or something because I am picking it out   
   >> of a list.   
   >>   
   >> The console may have a message that means something but it closes right   
   >> away.   
   >>   
   >> Also, the file is created to it obviously got past the script to the Flat   
   >> File Destination since that file is created and that is where it is   
   >> referenced.   
   >>   
   >> Thanks,   
   >>   
   >> Tom   
   >>   
   >> "Bob Barrows"  wrote in message   
   >> news:ihkpb0$fuc$1@news.eternal-september.org...   
   >>> tshad wrote:   
   >>>> In 2008, I have a package that works fine where I am getting rows   
   >>>> from my sql query and then I pass that to a Derived Column   
   >>>> Transformation which goes to a Script Task that just write a piece of   
   >>>> text and that goes to a Flat File Destination.   
   >>>>   
   >>>> In the Script task, I have the following:   
   >>>>   
   >>>>     public override void CreateNewOutputRows()   
   >>>>     {   
   >>>>         /*   
   >>>>           Add rows by calling the AddRow method on the member   
   >>>> variable named "Buffer".   
   >>>>           For example, call MyOutputBuffer.AddRow() if your output   
   >>>> was named "MyOutput".   
   >>>>         */   
   >>>>         Output0Buffer.AddRow();   
   >>>>         Output0Buffer.Resultstext = "This is a test: ";   //   
   >>>> +Convert.ToString(Variables.RowCnt);   
   >>>>     }   
   >>>>   
   >>>> I also have a User Variable RowCnt that gives me the number of rows   
   >>>> sent.   
   >>>>   
   >>>> This works fine.  I comment out the Convert statement because at this   
   >>>> point you cannot see the variable since I don't have it set up as a   
   >>>> ReadOnlyVariable.   
   >>>>   
   >>>> The file gets created with:   
   >>>>   
   >>>> Column 0   
   >>>> This is a test:   
   >>>>   
   >>>> But I also want to pass RowCnt so I can display it so I select   
   >>>> User::RowCnt from the list of ReadOnlyVariables.  Now in the Script I   
   >>>> can see RowCnt in the Variables list.  But I don't change the code at   
   >>>> all and I now get an error.   
   >>>   
   >>> I'm not sure I'm following your description correctly. Perhaps this will   
   >>> help ... ?   
   >>> http://whiteknighttechnology.com/cs/blogs/brian_knight/archi   
   e/2005/12/30/57.aspx   
   >>>   
   >>>   
   >>>   
   >>   
   >>   
   >   
   >   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca