Exception Message Box

A little-known component that comes with SQL Server 2005 is the exception message box (EMB) – I am sure you would have seen this anytime you work with SQL Server Management Studio (or Express).





It is almost a replacement for the standard message box (System.Windows.Forms.MessageBox) with the additional feature of displaying exceptions. It is a great UI component if you want to show detailed exception information (including inner/nested exceptions) to the end-user. What’s more – you can program almost every aspect of the exception message box: icon, number of buttons, button text, additional check box (remember ‘Do not show this message again’ option?) and much more.You can download the Exception Message Box from here.



A detailed how-to on EMB is also here.



Once installed, add a reference to Microsoft.ExceptionMessageBox.dll under [SYSDRIVE]:\Program Files\Microsoft SQL Server\90\SDK\Assemblies and you are all set to use it in your application. A simplest example is below:



using Microsoft.SqlServer.MessageBox;
... ...
try
{
}
catch (Exception xcp)
{
    ExceptionMessageBox emb = new ExceptionMessageBox (xcp);
    emb.Show();
}

A little customized exception message box:



ExceptionMessageBox emb = new ExceptionMessageBox (xcp);
emb.ShowCheckBox = true;
emb.Buttons = ExceptionMessageBoxButtons.OKCancel;
emb.CheckBoxText = "Do not show this message again";
emb.Symbol = ExceptionMessageBoxSymbol.Error;
emb.Show();

You can also have your own text for the buttons:



emb.Buttons = ExceptionMessageBoxButtons.Custom;
emb.SetButtonText ("Printer", "Clipboard", "File");

EMB redistributable (MSI package) is available with SQL Server 2005 SP1 which you can use to pack with your application.