I have already ask this question and I thought I found a solution but I am stuck yet again. I am having issues with unlock variables.
I'm running a SQL Server Agent Job which has a script task with Microsoft Visual C# 2008 which is below. I haven't listed the variables in Script task editor read/write variable list. In my SSIS package I have For Loop Container which loop over this script task until the file does exist.
https://mitchellsql.wordpress.com/2014/09/06/ssis-script-taskdoes-file-exists/
public void Main()
{
// Lock variables
Dts.VariableDispenser.LockForRead("User::FolderPath");
Dts.VariableDispenser.LockForWrite("User::FileExistsFlg");
// Create a variables 'container' to store variables
Variables vars = null;
// Add variables from the VariableDispenser to the variables 'container'
Dts.VariableDispenser.GetVariables(ref vars);
string filepath;
filepath = vars["User::FolderPath"].Value.ToString();
vars["User::FileExistsFlg"].Value = File.Exists(filepath);
// Release the locks
vars.Unlock();
Dts.TaskResult = (int)ScriptResults.Success;
}
}
}
Error
I get this error when the SQL Job fails but the package runs perfectly when run via Visual Studio:
Message
Executed as user: PSFACAMDWHSQL1\SYSTEM. Microsoft (R) SQL Server Execute Package Utility Version 10.50.4270.0 for 64-bit Copyright (C) Microsoft Corporation 2010. All rights reserved. Started: 12:26:43 Error: 2015-03-03 12:41:25.79 Code: 0xC001404F
Source: For Loop Container Description: This Variables collection has already been unlocked. The Unlock method is called only once on a dispensed Variables collection. End Error DTExec: The package execution returned DTSER_FAILURE (1). Started: 12:26:43 Finished: 12:41:25 Elapsed: 881.921 seconds. The package execution failed. The step failed.
I would appreciate any help.