Create a MessageBox in SSIS with C#

You can write SQL which outperforms and is bug free.

Get your copy of my SQL Best Practices and start writing the SQL which sails through code reviews.

Cost? Pay what you want :)

Student or just starting your career? Give yourself a break and get it for free.

Database professional? Think about your hourly rate and how much time you'll save with crisp and clear best practices.
Contribute over $27 and I'll send you the Word version of the doc so you can easily customize it for yourself and your team.

Get SQL Best Practices

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: , , , , , , , ,

No comments yet.

Leave a Reply