D B
asked on
SSIS C# Script Task Hangs
I have the following code in an SSIS C# Script task. It hangs on me and I've tried several ways to get it to run with no success. The object is, if a parameter named paramclientlist is empty, read the value from a configuration table, otherwise use the current value of the parameter. So, if the package is called with a value for parameterclientlist, that value will be retained.
In the code below, the configuration table has three rows of data, one of them having a value of paramclientlist for the column ConfigurationName. It is the last of the three values that is processed. When the code gets to the line
I've tried several things, including defining the parameter as a ReadOnlyVariable, a ReadWriteVariable, not defining it as either (which throws an error, I assume because I am setting the variable cientList to its value in the script) but nothing works. Interestingly, the other two parameter values I set work fine, and neither is set as a read only or read-write variable in the script task properties window. Does anyone have any clue how I can get this to work (VS 2017).
In the code below, the configuration table has three rows of data, one of them having a value of paramclientlist for the column ConfigurationName. It is the last of the three values that is processed. When the code gets to the line
Dts.VariableDispenser.LockOneForWrite(parmName, ref variables);
for the parmName paramclientlist, it 'hangs' like it is locked trying to get the lock. I don't know if it will eventually time out with an exception but after a couple of minutes I got tired of waiting and killed it.I've tried several things, including defining the parameter as a ReadOnlyVariable, a ReadWriteVariable, not defining it as either (which throws an error, I assume because I am setting the variable cientList to its value in the script) but nothing works. Interestingly, the other two parameter values I set work fine, and neither is set as a read only or read-write variable in the script task properties window. Does anyone have any clue how I can get this to work (VS 2017).
try
{
//get package name from variable passed in via dtexec
string packageName = "";
string clientList = "";
packageName = (string)Dts.Variables["paramclientconfig"].Value + "-" + (string)Dts.Variables["paramprocess"].Value;
clientList = (string)Dts.Variables["paramclientlist"].Value;
// We are now going to grab all of the actual configurations
// for the environment, and apply them to the package variables.
using (OleDbConnection SQLOper = new OleDbConnection(Dts.Connections["SQLOPS.operations"].ConnectionString))
{
SQLOper.Open();
// Calls a procedure that returns a pairing of user variables
// and what they should be set to.
using (OleDbCommand getConfigurations = new OleDbCommand("dbo.procGetApplicationConfigurations ?;", SQLOper))
{
// Sets values for the stored proc
getConfigurations.Parameters.AddWithValue("@ApplicationName", packageName);
// Allows us to iterate through the results set coming from the getConfigurations call
using (OleDbDataReader configurations = getConfigurations.ExecuteReader())
{
while (configurations.Read())
{
// Gets the values from the columns and sets the parameters
string parmName = "User::" + configurations["ConfigurationName"].ToString();
string parmValue = configurations["ConfigurationValue"].ToString();
// IF the variable exists in the DTS variable set
// It then sets with the configuration from the server
if (Dts.VariableDispenser.Contains(parmName))
{
if ((parmName != "User::paramclientlist") || (parmName == "User::paramclientlist" && string.IsNullOrEmpty(clientList)))
{
Dts.VariableDispenser.LockOneForWrite(parmName, ref variables);
Variable var = variables[parmName];
var.Value = Convert.ChangeType(parmValue, var.DataType);
}
}
}
}
}
}
}
finally
{
// Finally, makes sure that the variables are all unlocked before moving out of the script task
if (variables != null && variables.Count > 0)
{
variables.Unlock();
}
}
Dts.TaskResult = (int)ScriptResults.Success;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER