I have built the following code in my global.asax code
My question is how and when does the Sub application_start know when to start?
What must I do to trigger it to start and send an email?
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application is started
Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("c onnectionString"))
myConnection.Open()
'2. Create the command object, for the query
Const strSQL As String = "Select LastUpdated, ProductId from products "
Dim objCmd As New SqlCommand(strSQL, myConnection)
Dim objDR As SqlDataReader
objDR = objCmd.ExecuteReader()
While (objDR.Read)
'look the code is looking for DATETIME .. but it found NULL values
'need this code to keep from getting errors if a null is found
'we need to put some check for nulls
If (Not (objDR("LastUpdated") Is DBNull.Value)) Then
If (Date.Compare(objDR("LastUpdated"), Today.Date) = 0) Then
Dim newMail As New MailMessage
newMail.From = "
[email protected]" '' this is the From Address
newMail.To = "
[email protected]" '' this is TO Address
newMail.Subject = "Change in Product Rate"
newMail.Body = " Dear Ken, " & _
"Please review attached email for product ID: " & objDR("ProductID") & _
"Thank you," & _
"Kenn()"
End If
End If
End While
myConnection.Close() 'Close the connection
End Sub