SQL Server Cannot get SSIS Script Task to work

axr492tv  于 2023-10-15  发布在  其他
关注(0)|答案(4)|浏览(130)

I feel like I am missing some configuration or something, because I have followed tons of tutorials online, but cannot get any examples of a script task to work. I cannot debug the error either because I am not a C# developer.

Currently, I am simply checking if a file exists in a directory:

  1. User::gvLastMonthImportFile is string (read-only) & User::gvLastMonthImportFileExists is Boolean (read-write)

  2. Added using System.IO; to my namespaces

string fullPath = Dts.Variables["User::gvLastMonthImportFile"].Value.ToString();
Dts.Variables["User::gvLastMonthImportFileExists"].Value = File.Exists(fullPath);
Dts.TaskResult = (int)ScriptResults.Success;`

ERROR:

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()

n3ipq98p

n3ipq98p1#

I ran into this recently and it was because I had not added the variables to the script.

You have to explicitly add ReadOnlyVariables/ReadWriteVariables to the script task for it to have any access to them by double-clicking the script task in the designer, selecting 'Script' on the right-hand side of the dialog and then clicking the ReadOnlyVariables/ReadWriteVariables drop down.

I know this reply is late but this caused me a lot of grief and hopefully it helps someone.

pprl5pva

pprl5pva2#

I had a similar problem, but I want to had a screenshot to help debug these cases : After closing the cryptic error prompt, watch into your debug output, there will be a short yet more useful error message :

7bsow1i6

7bsow1i63#

Steps to run

  1. adding 2 lines code in the script.
Messagebox.Show(Dts.Variables["User::gvLastMonthImportFile"].Value.ToString());
Messagebox.Show(File.Exists(fullPath).Value.ToString());
  1. save and close the script, OK script task.
  2. right click script task, execute the task.
  3. when task is executing, the message will pop up. Please verify the data.

agxfikkp

agxfikkp4#

I had that same problem and was stuck for a couple of hours. Then I found my problem. Variables are case-sensitive and I had misspelled one of them.

相关问题