when does the Sub application_start know when to start?
-
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("connectionString")) 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 = "from@from.com" '' this is the From Address newMail.To = "kenn_rosie@msn.com" '' 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
-
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("connectionString")) 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 = "from@from.com" '' this is the From Address newMail.To = "kenn_rosie@msn.com" '' 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
It runs when your ASP.NET app spins up for the first time. Christian Graus - Microsoft MVP - C++
-
It runs when your ASP.NET app spins up for the first time. Christian Graus - Microsoft MVP - C++
Not quite sure what that means.... example, in my code I updated a db field that was placed in a word document, then I have the sub application_start send it email. I did that earlier today but have not received the email back yet, so I was wondering if I have to write code that causes the sub application_start to start?
-
Not quite sure what that means.... example, in my code I updated a db field that was placed in a word document, then I have the sub application_start send it email. I did that earlier today but have not received the email back yet, so I was wondering if I have to write code that causes the sub application_start to start?
kenn_rosie wrote:
so I was wondering if I have to write code that causes the sub application_start to start?
No, but unless you restart IIS, this code won't run. It gets run when IIS starts. Christian Graus - Microsoft MVP - C++
-
kenn_rosie wrote:
so I was wondering if I have to write code that causes the sub application_start to start?
No, but unless you restart IIS, this code won't run. It gets run when IIS starts. Christian Graus - Microsoft MVP - C++
hmm, so How do I get it to work to send out email without restarting IIS, That seems strange? If I want the email to go out daily, do I need to have a trigger or something to restart IIS all the time?
-
hmm, so How do I get it to work to send out email without restarting IIS, That seems strange? If I want the email to go out daily, do I need to have a trigger or something to restart IIS all the time?
No need to restart IIS daily for purpose of sending mail .Restarting IIS means restarting application . If you want to automatically send email daily , then create a small exe In which can be scheduled to run once in a day .This exe can be created in vb / vb.net . Divya Rathi