Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

Passing an object var from parent to child in a loop. Object doesn't keep value after first loop?

$
0
0

Hello -

I have a parent package that calls a child package. The parent parses a file, puts that data into an object variable, calls a child package 350+ times and passes that object variable own to the child to have it insert the data. Each time the child gets called, it's a different database.

The first time the parent calls the child, it works like a charm. (41,000+ records inserted)

Every other time, the object variable apparently loses the data, because 0 rows are inserted. I don't know if it loses it in the Parent package or the Child package.

I'm using simple script tasks to set the child variable equal to the parent, and then later to add that data to an output buffer. However, because I can only get the breakpoints to hit once, I'm struggling to debug.

Any help or ideas would be very appreciated.

I've put the script code below, if it helps.Although since it works on the first loop, I doubt anything there needs to be changed.

Thanks,
Scott

This is an Script Task

public void Main()
{
/*
*  This will copy over the parent package's uvar_zip_code_data to a local variable. 
*/

Variables vars = null;

// Child Variable
Dts.VariableDispenser.LockForWrite("User::uvar_zip_code_data_local");
// Parent Variable
Dts.VariableDispenser.LockForRead("User::uvar_zip_code_data");

Dts.VariableDispenser.GetVariables(ref vars);

// Set them equal to each other. 
vars["User::uvar_zip_code_data_local"].Value = vars["User::uvar_zip_code_data"].Value;

vars.Unlock();

Dts.TaskResult = (int)ScriptResults.Success;

}

This is a Script Transformation Editor defined as a source.

public override void CreateNewOutputRows()
{
  DataTable dt = new DataTable();
  OleDbDataAdapter olead = new OleDbDataAdapter();
       
  olead.Fill(dt, Variables.uvarzipcodedatalocal);

  foreach (DataRow row in dt.Rows)
  {
    ZipCodesBuffer.AddRow();
    ZipCodesBuffer.ZipCode = row["zipcode"].ToString();
    ZipCodesBuffer.State = row["state"].ToString();
    ZipCodesBuffer.City = row["city"].ToString();
    ZipCodesBuffer.County = row["county"].ToString();
  }
}




Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>