SSIS - Script Task error: Exception has been thrown by the target of an invocation.
Question:
When i execute the SSIS package the Script Task throws the following exception:
Answer:
When i execute the SSIS package the Script Task throws the following exception:
Which is meaningless. How can i read the real error message?Exception has been thrown by the target of an invocation.at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[]
arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams) at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()
Answer:
Exception has been thrown by the target of an invocation.
Is an general exception that is thrown by Script Task when an error occurred
Reading the real error message
To read the main error message you can add a try catch clause into your code and use Dts.FireError() method to throw the real exception.
public void Main()
{
try{
//...write your code here
Dts.TaskResult = (int)ScriptResult.Success;
}catch(Exception ex){
Dts.FireError(0,"An error occured", ex.Message,String.Empty, 0);
Dts.TaskResult = (int)ScriptResult.Failure;
}
}
Comments
Post a Comment