Error handler is not being triggered in global.asax.vb. VS 2005 SQL Server 2005
The breakpoint in the event handler was not tirggered during debug.
For clarification, here is my code:
Global.asax
<%@ Application Language="VB" Codebehind="Global.asax.vb
" %>
Global.asax.vb
Imports System.Web
Imports System.Net.Mail
Imports System.Text
Imports System.Web.SessionState
Imports System.Diagnostics
Imports System.Exception
Public Class Global1
Inherits System.Web.HttpApplication
#Region " Component Designer Generated Code "
Public Sub New()
MyBase.New()
'This call is required by the Component Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Required by the Component Designer
Private components As System.ComponentModel.ICon
tainer
'NOTE: The following procedure is required by the Component Designer
'It can be modified using the Component Designer.
'Do not modify it using the code editor.
<System.Diagnostics.Debugg
erStepThro
ugh()> Private Sub InitializeComponent()
components = New System.ComponentModel.Cont
ainer()
End Sub
#End Region
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application is started
End Sub
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the session is started
End Sub
Sub Application_BeginRequest(B
yVal sender As Object, ByVal e As EventArgs)
' Fires at the beginning of each request
End Sub
Sub Application_AuthenticateRe
quest(ByVa
l sender As Object, ByVal e As EventArgs)
' Fires upon attempting to authenticate the use
End Sub
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Dim ErrorDescription As String = Server.GetLastError().ToSt
ring
'Creation of event log if it does not exist
Dim EventLogName As String = "ErrorSample"
If (Not EventLog.SourceExists(Even
tLogName))
Then
EventLog.CreateEventSource
(EventLogN
ame, EventLogName)
End If
' Inserting into event log
Dim Log As New EventLog
Log.Source = EventLogName
Log.WriteEntry(ErrorDescri
ption, EventLogEntryType.Error)
Dim objClient As New SmtpClient
Dim objEMail As New MailMessage
Dim strErrorMessage As String = _
"The error description is as follows : " _
& Server.GetLastError().ToSt
ring()
'Try
Dim msg1 As New System.Net.Mail.MailMessag
e
objEMail.From = New MailAddress("dovberman@cab
leone.net"
)
objEMail.To.Add(New MailAddress("dmartin@resli
nker.com")
)
objEMail.Subject = "My Stock Picker Error Report"
objEMail.Body = strErrorMessage
'objEMail.Body = BuildMessage()
'objEMail.AlternateViews
msg1.Priority = MailPriority.Normal
objClient.Host = "localhost"
Try
objClient.Send(objEMail)
Response.Write("Your E-mail has been sent sucessfully")
Catch ex As Exception
Response.Write("Send failure: " + ex.ToString())
End Try
End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the session ends
End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application ends
End Sub
--------
Error that should be handled
xxx.asax file
<tr>
<td align=left colspan=1 style="height: 15px; width: 200px;" valign="top">
<asp:GridView ID="grdMarket" runat="server" AutoGenerateColumns="False
"
DataKeyNames="MarketID"
DataSourceID="dscMarket" Caption="Select a Market">
<Columns>
<asp:CommandField ShowSelectButton="True" ButtonType="Button" />
<asp:BoundField DataField="MarketName" HeaderText="Market Name" SortExpression="MarketName
" />
<asp:BoundField DataField="MarketID" HeaderText="MarketID" ReadOnly="True" SortExpression="MarketID" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="dscMarket" runat="server" ConnectionString="<%$ ConnectionStrings:StockSel
ectConnect
ionString %>"
ProviderName="System.Data.
SqlClient"
SelectCommand="SELECT [MarketName], [MarketID] FROM [Market1] ORDER BY [MarketID]">
</asp:SqlDataSource>
'Market1 is not the correct table name.
The error was displayed the normal way during debug and never got sent to the error handler.
Any ideas would be appreciated.
Start Free Trial