简体   繁体   English

无法让 SSIS 脚本任务工作

[英]Cannot get SSIS Script Task to work

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.我也无法调试错误,因为我不是 C# 开发人员。

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) 1) User::gvLastMonthImportFile是字符串(只读)& User::gvLastMonthImportFileExists是布尔值(读写)

2) Added using System.IO; 2) using System.IO;添加using System.IO; to my namespaces到我的命名空间

3) 3)

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()在 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) 在 System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] 修饰符,CultureInfo 文化, String[] namedParams) 在 Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()

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.您必须明确地将 ReadOnlyVariables/ReadWriteVariables 添加到脚本任务中,以便它可以通过双击设计器中的脚本任务来访问它们,选择对话框右侧的“脚本”,然后单击 ReadOnlyVariables/ ReadWriteVariables 下拉。

I know this reply is late but this caused me a lot of grief and hopefully it helps someone.我知道这个回复晚了,但这给我带来了很多悲伤,希望它可以帮助某人。

Steps to run运行步骤

  1. adding 2 lines code in the script.在脚本中添加 2 行代码。

     Messagebox.Show(Dts.Variables["User::gvLastMonthImportFile"].Value.ToString()); Messagebox.Show(File.Exists(fullPath).Value.ToString());
  2. save and close the script, OK script task.保存并关闭脚本,确定脚本任务。

  3. right click script task, execute the task.右键单击脚本任务,执行任务。

  4. when task is executing, the message will pop up.当任务正在执行时,会弹出消息。 Please verify the data.请核实数据。

脚本窗口的右侧是否有任何警告?

在此处输入图片说明

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.变量区分大小写,我拼错了其中之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM