Create a MessageBox in SSIS with C#

Banner will redirect to landing page with Certification Track courses.

What is wrong with me?!?  Or rather what is wrong with everyone else on the internet?  Why won't anyone post a little article on how to create a message box in an SSIS package so I can easily google it?  Must I do everything around here?

Confession: I don't know jack about C#.  Creating a message box is probably one of the most basic tasks ever but having never written any C# I can never remember how to do this and I can never find a blog post on how to do it.  Essentially, when it comes to creating a message box to check the state of a variable in SQL Server Integration Services I'm like the guy in Momento.  (Bam! Momento.  Best amnesia movie ever?  Probably.  Hmm, perhaps I should take a Polaroid of the code to help me remember...)

Why do I have "MessageBox.Show(Dts.Variables["YourVariableHere"].Value.ToString())" tattooed on my arm?

So without further ado.

  1. Add a Script Task to your Control Flow. Note: "Script Task" not "ActiveX Script Task".
  2. Open the task and click the "Edit Script" button near the bottom of the window.
  3. Scroll to the bottom of the default code and replace
            public void Main()
                // TODO: Add your code here
                Dts.TaskResult = (int)ScriptResults.Success;


     public void Main()
  4. Save and close the ssisscript window.
  5. Then, add your variable to the ReadOnlyVariables section.
  6. Click OK

That should do the trick.  Hopefully, writing this post will do the trick for me and help me remember how to do this (and I won't have to resort to Polaroids and tattoos.)


Tags: , , , , , , , ,

8 Responses to “Create a MessageBox in SSIS with C#”

  1. Flash Gordon May 7, 2013 at 4:20 pm #

    I found that I had to add a using to get this to work in my vs2008 environment. I needed:
    using microsoft.sqlserver.dts.runtime.tasks;

    to get what he describes above to compile. It doesn't know what "variables" after dts is unless you do this.

  2. Flash Gordon May 8, 2013 at 2:57 pm #

    Here is a working example of messagebox on ssis 2012:

    MessageBox.Show("file size is: " + Dts.Variables["User::FileSize"].Value.ToString() + " attributes are: " + Dts.Variables["User::FileAttributes"].Value.ToString()
    + " creation date :" + Dts.Variables["User::FileCreationDate"].Value.ToString());

  3. Phil Steffek May 16, 2013 at 2:58 pm #

    Good stuff! Thanks Flash!

  4. Ye-Chan December 18, 2013 at 5:38 am #

    Just FYI, if not there already, add a reference to the System.Windows to your code.

  5. Phil Steffek December 24, 2013 at 1:05 pm #

    Thanks for the tip!

  6. Kathie April 25, 2014 at 8:09 am #

    Thank you! Fabulously helpful.

  7. Phil Steffek May 7, 2014 at 4:18 pm #

    Glad to help Kathie!

  8. David May 8, 2014 at 3:19 pm #

    Thanks for that. It was that damn Step 5 that I was forgetting!!! Grrr!

Leave a Reply