Create a MessageBox in SSIS with C#

Free copy of SQL Best Practices?

Get your copy of SQL Best Practices and be the database developer that has rocket fuel in his veins.
Even better? These Best Practices are written in an easy to understand format so your whole team will quickly want to adopt them.
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