Solved

Error Reporting

Posted on 2006-11-07
3
380 Views
Last Modified: 2012-08-13
Instead of a VB.NET WIndows Application error occuring when something like a SQL Query is messed up or something or anyting at that matter that a standard user would have no clue what it means, can I have a custom error display, and then it send an email or something with the workstation or username that it errored out on to am SMTP address?  I have a HUGE application that many custom arguments are used against, and half the time my users never tell me if something is wrong or not, hence, I have no way of tracking things.

I could probably get the SMTP to work, but I need to know if this option is availabe on Windows Applications.  I know I can do it with a web application quite simply!!!

Thanks,
CR
0
Comment
Question by:chrisryhal
3 Comments
 
LVL 10

Expert Comment

by:gangwisch
Comment Utility
they have a control called the errorprovider to where you can validate your exceptions and a red exclamation point will show up if an error exists.
0
 
LVL 14

Accepted Solution

by:
ptakja earned 500 total points
Comment Utility
This is for Visual Studio 2005...

Include System.Net above your class declaration


        Dim msg As New Mail.MailMessage                                                    'Create new Message object

        'Build list of recipients (on my app, the TO textbox can contain a list of email addresses separated by ";"
        Dim recipients As String() = txtTo.Text.Split(CChar(";"))                      

        ' Configure the message object
        With msg
            .Subject = txtSubject.Text                                                                    'Subject field
            .Body = txtBody.Text                                                                              'Body

            ' Loop through recipients array adding recipients to the message.
            For ii As Integer = 0 To recipients.Length - 1
                .To.Add(New Mail.MailAddress(recipients(ii)))
            Next
            .Sender = New Mail.MailAddress("SenderAddres@YourDomain.com")         'Sender
            .Priority = Mail.MailPriority.Normal                                                           'Normal priority
            .From = .Sender                                                                                    'Set From address = to Sender

        End With

        ' Create new SMTPClient object, add the event handler for the SendCompleted and send the message.
        SMTPClient = New Mail.SmtpClient("YourSMTPServerAddress.com")

' Add handler for SendCompleted Async event. I use this event play a sound after the email has been sent.
        AddHandler SMTPClient.SendCompleted, AddressOf OnSendCompleted
        SMTPClient.SendAsync(msg, 1)



Here's the OnSendCompleted method referenced above to play the sound.

    ''' <summary>
    ''' Event handler for the SendComplete event. Plays the Send Mail system sound when the message has been sent.
    ''' </summary>
    ''' <param name="sender">Not used.</param>
    ''' <param name="e">Not used.</param>
    Private Sub OnSendCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)

        Dim ms As System.IO.UnmanagedMemoryStream = My.Resources.Send   'Get a Memory Stream from my resources.
        Dim snd As New System.Media.SoundPlayer(ms)                     'Instantiate a SoundPlayer object
        Call snd.Play()                                                 'Play the sound

        ' Cleanup
        Call snd.Dispose()
        Call ms.Dispose()
        Me.Close()                                                      'Close the form
    End Sub
0
 
LVL 2

Author Comment

by:chrisryhal
Comment Utility
AWESOME solution ptakja

I had to do some modification of course to tailor it what I wanted it to do, but your example worked nicely

Always appreciated!!!

CR
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now