2

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

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

Hadi
  • 36,233
  • 13
  • 65
  • 124
Pablo Boswell
  • 805
  • 3
  • 13
  • 30
  • That's not your error. That's a stack trace. There must be more to the error message than that. – Tab Alleman May 01 '17 at 15:37
  • How do I get the error? – Pablo Boswell May 01 '17 at 15:37
  • If I was a gambling man (I'm not) I would say you don't have permission on the folder. But as Tab Alleman noted there is more to the error message that you are showing us. – benjamin moskovits May 01 '17 at 15:39
  • Is the error in development mode (within the ide) or after deployment. If the former and you have sql2012 you can step through your code while it is debugging. – Steve May 01 '17 at 15:41
  • Please post your complete list of your namespaces. – Wendy May 01 '17 at 15:59
  • using System; using System.Data; using Microsoft.SqlServer.Dts.Runtime; using System.Windows.Forms; using System.IO; – Pablo Boswell May 01 '17 at 17:11
  • I am also running in debug as my own local user, so I should have permission to this folder. In fact, this is the same folder from which I am importing data files, so I know I have some permission. – Pablo Boswell May 01 '17 at 17:12
  • Are you 100% certain that `fullPath` is a valid path. I suggest you use a for each file loop instead of a script task to do this. – Nick.Mc May 02 '17 at 00:22
  • If I copy the rendered path from the variables into my file explorer, it opens the file. it is a shared network drive though, but my personal user account has access and I am running in debug using my local user profile. – Pablo Boswell May 08 '17 at 18:40

3 Answers3

2

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.

sidewinder
  • 21
  • 4
0

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

Is there any warning in the right hand side of script window?

enter image description here

Wendy
  • 640
  • 1
  • 4
  • 8
  • I added these lines, but an "Exception has been thrown by the target of an invocation" before it will even execute the script. If I "Close" that trace message, it fails the task. No outputs. – Pablo Boswell May 08 '17 at 18:45
  • Where did you run the code? in the script window? You must close it and execute the script task. – Wendy May 08 '17 at 18:54
  • No. I saved, clicked OK, and executed the task. At this point, I am wondering if it's some kind of DLL or library I am missing? – Pablo Boswell May 08 '17 at 19:51
  • I just added an image, is there any warning/error in your right hand side of script window? – Wendy May 08 '17 at 20:01
  • There are no warnings and I see the same references you have. Not sure if this means anything, but above `public void Main()` it says "0 references" – Pablo Boswell May 08 '17 at 20:49
  • I added another image. No idea what "0 references" is. – Wendy May 09 '17 at 13:57
  • Script Tasks should be configured to run out-of-the-box right? – Pablo Boswell May 09 '17 at 18:18
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/143810/discussion-between-wendy-and-pablo-boswell). – Wendy May 09 '17 at 18:22
0

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.

Raul
  • 1