Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. when does the Sub application_start know when to start?

when does the Sub application_start know when to start?

Scheduled Pinned Locked Moved Visual Basic
databasequestioncom
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kenn_rosie
    wrote on last edited by
    #1

    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

    C 1 Reply Last reply
    0
    • K kenn_rosie

      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

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      It runs when your ASP.NET app spins up for the first time. Christian Graus - Microsoft MVP - C++

      K 1 Reply Last reply
      0
      • C Christian Graus

        It runs when your ASP.NET app spins up for the first time. Christian Graus - Microsoft MVP - C++

        K Offline
        K Offline
        kenn_rosie
        wrote on last edited by
        #3

        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?

        C 1 Reply Last reply
        0
        • K kenn_rosie

          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?

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          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++

          K 1 Reply Last reply
          0
          • C Christian Graus

            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++

            K Offline
            K Offline
            kenn_rosie
            wrote on last edited by
            #5

            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?

            D 1 Reply Last reply
            0
            • K kenn_rosie

              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?

              D Offline
              D Offline
              Divya Rathi
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups