none
SSIS C# Script Task, How to Display User Variable?

    Question

  • It's been a while since I used SSIS. Back when I used it several years ago, the script task used to be VB, but now BIDS is showing C# 2008 as the script language. So how do I display variable values using C#'s MessageBox?

    So far, what I have is:

    (1) A file loop container looping through a folder and assigning the file name to a package variable.

    (2) In the container I have a script task, and the variable is populated in the "ReadOnlyVariables" box of the Script Task Editor. (I believe this is what makes the variable visible in the Script Task, if I remember things correctly. The package variable I am using happens to be called "FileName".

    (3) I open the Script Editor and I put this in.

    public void Main()
            {
                MessageBox.Show(Dts.Variables["FileName"].Value.ToString())
            }

    But there must be something wrong with this because when I save the script and get back to the Control Flow, the script task has that red x on it. And when I hover over it, it is complaining "The binary code for the script is not found." And it goes on to say go back and edit the script.
    Wednesday, June 06, 2012 4:19 PM

Answers

  • Script task can be VB.Net or C# depending on what you select when you first create it.

    c# needs a ; (semicolon) at the end of each line

    MessageBox.Show(Dts.Variables["FileName"].Value.ToString());


    Chuck Pedretti | Magenic – North Region | magenic.com


    Yep, that fixed it. And now that you mention it, I do see that there is an option to choose the language when you first create the task.

    Another quick question since you seem to be jumping on these questions very quickly.... Can I put a filter condition on a file enumerator? For example, after specifying the folder and the file extension, can I further narrow down the search criteria by specifying something like "where the file created date is between these dates"?

    • Marked as answer by D00linDalton Wednesday, June 06, 2012 7:05 PM
    Wednesday, June 06, 2012 4:29 PM
  • I don't think so.  For that I think you would need to use a script task to eliminate the files inside the loop you don't want by looking at the created date via a FileInfo object or something like that.

    Chuck Pedretti | Magenic – North Region | magenic.com

    • Marked as answer by D00linDalton Wednesday, June 06, 2012 7:05 PM
    Wednesday, June 06, 2012 5:31 PM

All replies

  • Script task can be VB.Net or C# depending on what you select when you first create it.

    c# needs a ; (semicolon) at the end of each line

    MessageBox.Show(Dts.Variables["FileName"].Value.ToString());


    Chuck Pedretti | Magenic – North Region | magenic.com


    Wednesday, June 06, 2012 4:23 PM
  • Script task can be VB.Net or C# depending on what you select when you first create it.

    c# needs a ; (semicolon) at the end of each line

    MessageBox.Show(Dts.Variables["FileName"].Value.ToString());


    Chuck Pedretti | Magenic – North Region | magenic.com


    Yep, that fixed it. And now that you mention it, I do see that there is an option to choose the language when you first create the task.

    Another quick question since you seem to be jumping on these questions very quickly.... Can I put a filter condition on a file enumerator? For example, after specifying the folder and the file extension, can I further narrow down the search criteria by specifying something like "where the file created date is between these dates"?

    • Marked as answer by D00linDalton Wednesday, June 06, 2012 7:05 PM
    Wednesday, June 06, 2012 4:29 PM
  • I don't think so.  For that I think you would need to use a script task to eliminate the files inside the loop you don't want by looking at the created date via a FileInfo object or something like that.

    Chuck Pedretti | Magenic – North Region | magenic.com

    • Marked as answer by D00linDalton Wednesday, June 06, 2012 7:05 PM
    Wednesday, June 06, 2012 5:31 PM
  • I don't think so.  For that I think you would need to use a script task to eliminate the files inside the loop you don't want by looking at the created date via a FileInfo object or something like that.

    Chuck Pedretti | Magenic – North Region | magenic.com


    Yes, I was hoping you would tell me otherwise, but I think you need to still go through the whole list and filter out some other way.
    Wednesday, June 06, 2012 7:05 PM