Home - Client Software (zip) - Client Installation - Compiling Client - Trace Latency Tool - Site Terms of Use

Here is the source code for the AreWeDown service:



Imports System.ServiceProcess
Imports System
Imports Microsoft.Data.Odbc

Public Class AreWeDown
    Inherits System.ServiceProcess.ServiceBase

#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

    'UserService overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    ' The main entry point for the process
     _
    Shared Sub Main()
        Dim ServicesToRun() As System.ServiceProcess.ServiceBase

        ServicesToRun = New System.ServiceProcess.ServiceBase() {New AreWeDown}

        System.ServiceProcess.ServiceBase.Run(ServicesToRun)
    End Sub

    'Required by the Component Designer
    Private components As System.ComponentModel.IContainer

    ' 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.
    Friend WithEvents Timer1 As System.Timers.Timer
    Private Sub InitializeComponent()
        Me.Timer1 = New System.Timers.Timer
        CType(Me.Timer1, System.ComponentModel.ISupportInitialize).BeginInit()
        '
        'Timer1
        '
        Me.Timer1.Enabled = True
        Me.Timer1.Interval = 30000

        Me.ServiceName = "AreWeDown.com"
        CType(Me.Timer1, System.ComponentModel.ISupportInitialize).EndInit()

    End Sub

#End Region

    Protected Overrides Sub OnStart(ByVal args() As String)
        ' Add code here to start your service. This method should set things
        ' in motion so your service can do its work.
        Timer1.Enabled = True
    End Sub

    Protected Overrides Sub OnStop()
        ' Add code here to perform any tear-down necessary to stop your service.
        Timer1.Enabled = False
    End Sub

    Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As _
 System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
        Dim MyConString As String = "DRIVER={MySQL ODBC 3.51 Driver};" & _
                           "SERVER=arewedownhost;" & _
                           "DATABASE=arewedown;" & _
                           "UID=are;" & _
                           "PASSWORD=arepass;" & _
                           "OPTION=3;"
        Dim MyConnection As New OdbcConnection(MyConString)
        MyConnection.Open()

        Dim MyCommand As New OdbcCommand
        MyCommand.Connection = MyConnection
        MyCommand.CommandText = "INSERT INTO stats VALUES(CURRENT_TIMESTAMP,USER(),100)"
        MyCommand.ExecuteNonQuery()
        MyCommand.CommandText = "INSERT INTO stats VALUES(CURRENT_TIMESTAMP,USER(),101)"
        MyCommand.ExecuteNonQuery()
        MyConnection.Close()

    End Sub

    Protected Overrides Sub Finalize()
        MyBase.Finalize()
    End Sub
End Class

This was written in Visual Basic .NET 2003. In addition to the .NET framework, you need the MySQL ODBC client and the ODBC .NET Data Provider from:

MySQL Connector/ODBC 3.51 Downloads
ODBC .NET Data Provider


After you add the ODBC .NET Data Provider, you need to make sure that the Microsoft.Data.Odbc namespace is checked by customizing the toolbox in the Visual Basic .NET IDE. Right-click on the toolbox and choose Add/Remove Items. Also, you man need to add the reference under Project->Add Reference. I used Microsoft.Data.ODBC.dll version 1.0.3300.0.

I found these resources quite useful in figuring out how to do the above:

The VB.NET-MySQL Tutorial - Part 6
Creating a SQL Server Database Programmatically using VB.NET
OdbcCommand.ExecuteNonQuery Method (System.Data.Odbc)
.NET Framework Class Library: OdbcConnection Class
.NET Framework Class Library: SqlConnection Class
Creating a Windows Service in VB.NET - Adding an Installer to the Project
MySQL Reference Manual :: 25.1.20.2 ODBC.NET: VB
Understanding ODBC .NET Data Provider
Configuring ISA Server 2000 MySQL Database Logging
PHP Tutorial - Inserting data into a MySQL Database
Using MySQL with Visual Studio


For other resources at AreWeDown Click Here.


Please read our Terms of Use

Copyright 2005-2007 AreWeDown.com