Visual Studio Development Bookmark and Share   
 index > Visual Studio Debugger > Windows service doesn't receive data from sql server
 

Windows service doesn't receive data from sql server

Here is my code:

When I get to fill the first adapter, which is trying to retrieve a lot of data, the process just stops or doesn't move. The SQL statement is sent to the database, I viewed it in SQL Profiler, so I'm wondering why the data is not being accepted back. The query takes about 1 minute to process. Any help would be appreciated.

Imports System.Threading
Imports System.Diagnostics
Imports System.Net.Mail
Imports System.Net

Public Class UpdateCicmpyService

    Private job As ProcessJobV2
    Private processed As Boolean = False
    Private myTimer As New System.Timers.Timer
    Private timerThread As System.Threading.Thread
    Private Const midYearDate As String = "07/04/"
    Private Const endYearDate As String = "12/25/"
    Private _lastRun As Date
    Private _mailSent As Boolean = False

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        If Not EventLog.SourceExists("Tier") Then
            EventLog.CreateEventSource("Tier", "Customer Tier Update")
            Tier_EventLog.Source = "Tier"
            Tier_EventLog.WriteEntry("Event log created successfully")
        End If

        AddHandler myTimer.Elapsed, New System.Timers.ElapsedEventHandler(AddressOf CheckTime)
        myTimer.Interval = 10000

    End Sub

    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.

        myTimer.Enabled = True
        timerThread = New System.Threading.Thread(AddressOf myTimer.Start)
        timerThread.Start()

    End Sub

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

    Public Sub CheckTime()

        Dim midYear As Date = CType(midYearDate & Date.Now.Year, Date)
        Dim endYear As Date = CType(endYearDate & Date.Now.Year, Date)


        'If (Now.Month = 6 And Now.Day = 27) Or (Now.Month = 12 And Now.Day = 18) Then
        '    If _mailSent = False Then
        '        Dim warningMail As New MailMessage
        '        Debugger.Break()
        '        myTimer.Enabled = False
        '        warningMail.From = New MailAddress("EMAIL REMOVED")
        '        warningMail.To.Add(New MailAddress("EMAIL REMOVED"))
        '        warningMail.To.Add(New MailAddress("EMAIL REMOVED"))
        '        warningMail.To.Add(New MailAddress("EMAIL REMOVED"))
        '        warningMail.Subject = "Ortho Tier Service"
        '        warningMail.Body = "This is a reminder that the Ortho Tier Service will run one week from today. All customer tier information will be updated. This is an automated message " _
        '                                       & ", please do not reply. You should get an email when the Ortho Tier service is complete."
        '        warningMail.Priority = MailPriority.High

        '        Dim client As New SmtpClient
        '        client.Send(warningMail)
        '        _mailSent = True
        '    End If
        'Else
        '    _mailSent = False
        'End If

        'Debugger.Break()

        'If (Date.Now.ToShortDateString = midYear Or Date.Now.ToShortDateString = endYear) AndAlso Date.Now.ToShortDateString <> _lastRun Then
        myTimer.Enabled = False
        job = New ProcessJobV2
        job.Process()
        _lastRun = Now.ToShortDateString

        myTimer.Enabled = True
        Dim completeMail As New MailMessage

        completeMail.From = New MailAddress("EMAIL REMOVED")
        completeMail.To.Add(New MailAddress("EMAIL REMOVED"))
        'completeMail.To.Add(New MailAddress("EMAIL REMOVED"))
        'completeMail.To.Add(New MailAddress("EMAIL REMOVED"))
        completeMail.Subject = "Ortho Tier Service"
        completeMail.Body = "The Ortho Tier Service has completed"
        completeMail.Priority = MailPriority.High

        Dim client As New SmtpClient
        client.Send(completeMail)

        EventLog.WriteEntry("Tier", String.Format("Tier Service Complete on {0}", Now.ToShortDateString))

        'End If

    End Sub

End Class

 

 

Imports Ortho_Tier.OrthodataTableAdapters
Imports System.Data.SqlClient
Imports System.Net.Mail
Public Class ProcessJobV2

    Public Sub Process()
        Dim ordLinAdapt As New oelinhst_sqlTableAdapter
        Dim ordLinTable As New Orthodata.oelinhst_sqlDataTable
        Dim ordHdrAdapt As New oehdrhst_sqlTableAdapter
        Dim ordHdrTable As New Orthodata.oehdrhst_sqlDataTable
        Dim cusAdapt As New cicmpyTableAdapter
        Dim cusTable As New Orthodata.cicmpyDataTable
        Dim TotalCount As Integer = 0
        Dim bracketPercent As Integer = 0
        Dim bandPercent As Integer = 0
        Dim auxPercent As Integer = 0
        Dim i As Integer = 0
        Dim incCount As Integer = 0
        Dim increments As Integer = 0

        'ordHdrAdapt.FillWithin1YearSales(ordHdrTable)
        ordLinAdapt.FillWithin1yearSales(ordLinTable)

        cusAdapt.FillByDomesticCustomers(cusTable)

        Dim startTime As TimeSpan = DateTime.Now.TimeOfDay
        For Each cust As Orthodata.cicmpyRow In cusTable.Rows
            Dim bracketsCnt = From br In ordLinTable _
                              Where br.item_no >= "700-003" And br.item_no <= "799-339" And br.cus_no = cust.cmp_code

            Dim bands = From br In ordLinTable _
                              Where br.item_no >= "805-25905" And br.item_no <= "950-15609E" And br.cus_no = cust.cmp_code

            Dim auxCnt = From br In ordLinTable _
                              Where br.item_no >= "032-050" And br.item_no <= "650-018" And br.cus_no = cust.cmp_code

            Dim custPurchases = From cPur In ordLinTable _
                                Where cPur.cus_no = cust.cmp_code

            TotalCount = custPurchases.Count
            bracketPercent = (bracketsCnt.Count / TotalCount) * 100
            bandPercent = (bands.Count / TotalCount) * 100
            auxPercent = (auxCnt.Count / TotalCount) * 100

            Dim cusCustomer As New Customer(bracketPercent, bandPercent, auxPercent, cust.cmp_code)

            If bracketPercent >= 75 Then
                If bandPercent > 0 And auxPercent > 0 Then
                    cusCustomer.Tier = Tier.Three
                Else
                    cusCustomer.Tier = Tier.One
                End If
            ElseIf bracketPercent > 50 Then
                cusCustomer.Tier = Tier.One
            ElseIf bandPercent > 50 Then
                cusCustomer.Tier = Tier.Two
            ElseIf auxPercent > 50 Then
                cusCustomer.Tier = Tier.Four
            ElseIf auxPercent = 50 And bracketPercent = 50 Then
                cusCustomer.Tier = Tier.One
            ElseIf auxPercent = 50 And bandPercent = 50 Then
                cusCustomer.Tier = Tier.Two
            ElseIf bracketPercent = 50 And bandPercent = 50 Then
                cusCustomer.Tier = Tier.Three
            Else
                cusCustomer.Tier = Tier.Three
            End If


            cust.NumIntField1 = cusCustomer.Tier

            i += 1

            If i = 1000 Then
                incCount += 1
                i = 0
                Dim endTime As TimeSpan = DateTime.Now.TimeOfDay
                Dim difference As TimeSpan = endTime.Add(-startTime)
                EventLog.WriteEntry("Tier", String.Format("Increment {0} out of {1} increments completed, which took {2} amount of time", incCount, increments, difference))
                startTime = DateTime.Now.TimeOfDay
            End If
        Next

        Try
            cusAdapt.Update(cusTable)
        Catch ex As SqlException
            EventLog.WriteEntry("Tier", ex.Message)
            Dim warningMail As New MailMessage
            Debugger.Break()
            warningMail.From = New MailAddress("EMAIL REMOVED")
            warningMail.To.Add(New MailAddress("EMAIL REMOVED"))
            warningMail.To.Add(New MailAddress("EMAIL REMOVED"))
            warningMail.Subject = "Ortho Tier Service"
            warningMail.Body = "There was an error that occurred during processing: " + ex.Message
            warningMail.Priority = MailPriority.High

            Dim client As New SmtpClient
            client.Send(warningMail)
        End Try


    End Sub



End Class



MCTS
Mike Gerbi  Thursday, October 15, 2009 9:44 PM
Never mind, I found the problem.

A first chance exception of type 'System.OutOfMemoryException' occurred in System.Data.dll


MCTS
Mike Gerbi  Thursday, October 15, 2009 9:58 PM
Never mind, I found the problem.

A first chance exception of type 'System.OutOfMemoryException' occurred in System.Data.dll


MCTS
Mike Gerbi  Thursday, October 15, 2009 9:58 PM

You can use google to search for other answers

Custom Search

More Threads

• Is it possible to exclude my own classes from the debugger
• Insanely slow loading time with loading symbols for ntdll.dll
• Not prompted to choose debugger
• Help on problem with Vista & DevStudio 2005 Launching WebSites causes blank IE7 browser to appear
• Symbol server scaling?
• VS 2005 C++ COM ATL Debug mode slow performance
• "first-chance exception" message vs. dialog
• Debugger will not run in VS2005 and VS2008
• Where do I ask questions about debugging a .NET DLL called from a C++ application.
• Does remote debugging expose code?