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,098 of 19,505    |
|    tshad to tshad    |
|    Re: SSIS - Passing User Variables to scr    |
|    24 Jan 11 16:43:34    |
   
   From: tfs@dslextreme.com   
      
   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"
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca