SSIS Variable Dispenser Template


I don't write enough SSIS script blob tasks to commit this to memory. This is the safest way to access variables without inadvertantly locking them after a crash.

public void Main() {
  Variables vars = null;

  try {
    Dts.VariableDispenser.LockForWrite("User::strWritable");
    Dts.VariableDispenser.LockForRead("User::strReadable");

    Dts.VariableDispenser.GetVariables(ref vars);
    vars["User::strWritable"].Value = vars["User::strReadable"].Value.ToString();

    Dts.TaskResult = (int) ScriptResults.Success;
  }
  catch(Exception) {
    Dts.TaskResult = (int) ScriptResults.Failure;
  }
  finally {
    vars.Unlock();
  }
}


Tweet