Search code examples
c#sql-serverssisetlscript-task

SSIS Script Task with Read/Write Variables doesn't stop on ScriptResults.Failure


If I don't pass any variables to the script task, I can make it fail or succeed by setting the Dts.TaskResult. But When I pass some read/write variables, I can't make it fail (keeps executing forever), but I can still make it succeed.

Am I missing some settings? Please help.

I am using Sql Server 2012 (VS 2010 for BIDS). Script code:

Dts.TaskResult = (int)ScriptResults.Failure;
return;

Read/write variable passed:

User::FileName

Solution

  • Hadi, Thank you so much for responding, really appreciate it. I saw similar lock issues in other posts, tried it and failed. But I was able to understand the root cause myself later and I'm posting it so that it might save time for somebody else:

    I realized later that, in addition to above script task and readwrite variable, I had also used that ReadWrite variable in error handling event of the whole package. When a ReadWrite variable used in SSIS package is used in Error Handler, it makes the package to NOT fail even when exceptions happen or Dts.TaskResult is set to fail. Instead, it goes running in infinite loop! pretty wacky, eh? I wish Microsoft had planned to return some kind of validation error for using ReadWrite variable of script task in Error handler instead of an infinite execution...

    Anyway, I solved the problem by not using that ReadWrite variable in script task and setting it in some Expression task to be used by error handler.