4 Replies Latest reply: May 15, 2014 9:52 AM by RalphB _ RSS

    Server Threw an Exception

    RalphB _

      I have several scripts set up to create reports torun before I get in in the morning and I am frequently getting "Server Threw an Exception" error messages and everything grinds to a halt until I get in and get it started again. 

       

      It used to work flawlessly until fairly recently and it is not always the same script or the same location which really puzzles me.

       

      I do  most of my scripting in Excel VB because more people are familiar with it and they can run these scripts by themselves and add companies to run when I'm not here.

       

      I'm including the code for one process that I run.  This report is not the only one I get the error on, it just the one that caused problems today.  It opens several instances (16 companies in this case) of the same report, attaches a model and then applies 2 different filters that get exported out.

       

      This is done to 2 different reports.  This may lock up on the first part either opening a report or applying the model or on the second part.

       

       

      [font="courier"] Option Explicit

      Public myDate As Date

      Dim MonarchObj As Object

      Sub TransferRun()

       

      Transfer

      Do While IsServerActive()

          DoEvents

      Loop

       

      MonarchObj.CloseAllDocuments

      MonarchObj.exit

      Set MonarchObj = Nothing

       

      Open "G:AccountingPRM_ACTGLogsMonarchLogMornSchedule" & Month(Now()) & "-" & Day(Now()) & "-" & Year(Now()) & "MornSched.txt" For Append As #1

          Write #1, "Transfer completed at " & TimeValue(Now()) & "."

          Close #1

      End Sub

      Sub Transfer()

      If Range("E2") <> "" Then

          myDate = ActiveCell

          Else

          myDate = Date - 1

      End If

       

      Dim stPAReportNo As String, stGAReportNo As String, stCoNo As String, stReportPath As String

      Dim stModelPath As String, stPAModel As String, stGAModel As String, stExportPath As String

      Dim TempFile As String, stReportDate As String, stGASuspense As String, stGASuspPath As String

      Dim stMonth As String, stDay As String, stYear As String, stExportName As String

      Dim OpenFile As Boolean, OpenMod As Boolean, ExportFile As Boolean

      Dim stTransferFilter As String, stGASuspFilter As String, t As Boolean, ServerOn As Integer

       

      On Error GoTo Err_Transfer

       

      stPAReportNo = "N030000.000"

      stGAReportNo = "N188000.000"

      stPAModel = "TransferPA.xmod"

      stGAModel = "Transfer.xmod"

      stModelPath = "G:AccountingPRM_ACTGmodelCurrent"

      stExportName = "Transfer.xls"

      stExportPath = "G:AccountingPRM_ACTGSW Transfers"

      TempFile = "C:     empTransfer.txt"

      stExportPath = stExportPath & stExportName

      stGASuspense = "GA_Suspense.xls"

      stGASuspPath = "G:AccountingPRM_ACTGSW GA Suspense"

      stGASuspPath = stGASuspPath & stGASuspense

      stTransferFilter = "Transfer"

      stGASuspFilter = "218007"

       

      stDay = Day(myDate)

      If Len(stDay) = 1 Then

          stDay = "0" & stDay

      End If

       

      stMonth = Month(myDate)

      If Len(stMonth) = 1 Then

          stMonth = "0" & stMonth

      End If

       

      stYear = Year(myDate)

       

      stReportDate = stYear & stMonth & stDay

       

      Open TempFile For Output As #1

      Range("A1").Select

       

      Do While ActiveCell <> ""

          stCoNo = ActiveCell

          If Len(stCoNo) = 1 Then

              stCoNo = "0" & stCoNo

          End If

          Write #1, stCoNo

          ActiveCell.Offset(1, 0).Select

      Loop

      Close #1

       

      'Set MonarchObj = GetObject("", "Monarch32")

      'If MonarchObj Is Nothing Then

      ServerOn = IsServerActive()

      If ServerOn = 0 Then

          Set MonarchObj = CreateObject("Monarch32")

      End If

       

      t = MonarchObj.SetLogFile("G:AccountingPRM_ACTGLogsMonarchLog" & Month(myDate) & "-" & Day(myDate) & "-" & Year(myDate) & " SW Transfer log", True)

       

      Open TempFile For Input As #2

       

      Do While Not EOF(2)

      Input #2, stCoNo

      stReportPath = "R:" & stCoNo & "" & stReportDate & "" & stPAReportNo

       

      OpenFile = MonarchObj.SetReportFile(stReportPath, True)

      Application.Wait (Now + TimeValue("0:00:01"))

      Loop

      Close #2

      'If OpenFile = True Then

          OpenMod = MonarchObj.SetModelFile(stModelPath & stPAModel)

      'End If

      MonarchObj.CurrentFilter = stTransferFilter

      ExportFile = MonarchObj.JetExportTable(stExportPath, "Transfer", 2)

      Application.Wait (Now + TimeValue("0:00:01"))

      MonarchObj.CurrentFilter = stGASuspFilter

      ExportFile = MonarchObj.JetExportTable(stGASuspPath, "GA_Suspense", 2)

      MonarchObj.CloseAllDocuments

      Open TempFile For Input As #3

       

      Do While Not EOF(3)

      Input #3, stCoNo

       

      stReportPath = "R:" & stCoNo & "" & stReportDate & "" & stGAReportNo

       

      OpenFile = MonarchObj.SetReportFile(stReportPath, True)

      Application.Wait (Now + TimeValue("0:00:01"))

      Loop

      Close #3

      If OpenFile = True Then

          OpenMod = MonarchObj.SetModelFile(stModelPath & stGAModel)

      End If

      MonarchObj.CurrentFilter = stTransferFilter

      ExportFile = MonarchObj.JetExportTable(stExportPath, "Transfer", 2)

      Application.Wait (Now + TimeValue("0:00:05"))

      MonarchObj.CurrentFilter = stGASuspFilter

      ExportFile = MonarchObj.JetExportTable(stGASuspPath, "GA_Suspense", 2)

      'MonarchObj.exit

      'Set MonarchObj = Nothing

      Range("E2").Select

      Selection.ClearContents

      ActiveWorkbook.Save

      MonarchObj.exit

      Exit Sub

      Err_Transfer:

          MsgBox Err.Description

          Resume Next

           

      End Sub

       

       

      Function IsServerActive()

       

          On Error GoTo NoServer

          If MonarchObj.IsActive > 0 Then

              IsServerActive = 1

          End If

          Exit Function

      NoServer:

          IsServerActive = 0

          Exit Function

           

      End Function

      /font[/quote]Any help on solving this perplexing problem would be greatly appreciated.

       

      Running Monarch 8.02 Pro.

        • Server Threw an Exception
          Data Kruncher

          Hi Ralph!

           

          Does Gareth's response, or anything else discussed in  [url="http://mails.datawatch.com/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=1;t=001475;p=1#000006"]this similar thread[/url] help at all?

           

          Kruncher

          • Server Threw an Exception
            RalphB _

            Thanks Sandy,

             

            The trouble is I can't pinpoint where it will throw the error.  It may be on the first pass, it may be later on.

             

            Whe it happens, I hit "Debug" and look where it stopped and the path and file name look ok.  I hit F5 and it takes off running. 

            I really can't put a message box in to see what it looks like before because I have 17 scripts running in succession and each one may open from 1 to over 30 reports ("poor man's Datapump") that export out to excel or access and some of them are for people who start work before I come in.

             

            Like I said, it varies as to which script throws the exception and where in the script.  It worked great until about 3 or 4 months ago.  I also have been receiving "Waiting for another application  to finish" messages occasionally too.

             

            BTW, pc is running Windows XP Pro w/ office 2003 sp 2 installed 512 meg ram.

            • Server Threw an Exception
              Nick Osdale-Popa

              I took some liberties in re-working your code, hope you don't mind.

               

              First, I removed the code that writes the Company Number(?) to an external file and used a VB Collection instead .

               

              Then I added a Report Counter . This will count the number of reports loaded and as long as 1 report is loaded and if your Model is opened successfully will apply your filter(s) and export. Also, it only waits 1 second WHEN a report is loaded.

               

              I'm not sure what's causing the Exception Error, but those checks "hopefully" will eliminate it.  Perhaps, no reports were loaded and you were trying to apply a model and filters to "nothing", I can't really say.

               

              [font="courier"]Option Explicit

              Public myDate As Date

              Dim MonarchObj As Object

               

              Sub TransferRun()

               

                  Transfer

                  Do While IsServerActive()

                      DoEvents

                  Loop

               

                  MonarchObj.CloseAllDocuments

                  MonarchObj.Exit

                  Set MonarchObj = Nothing

                   

                  Open "G:AccountingPRM_ACTGLogsMonarchLogMornSchedule" & Format$(Date, "mm-dd-yyyy") & "MornSched.txt" For Append As #1

                  Write #1, "Transfer completed at " & TimeValue(Now()) & "."

                  Close #1

              End Sub

               

              Sub Transfer()

                  If Range("E2") <> "" Then

                      myDate = ActiveCell

                      Else

                      myDate = Date - 1

                  End If

               

                  Dim colCoNo As Collection

                  Dim varCoNo As Variant

                  Dim stLogFile As String

                  Dim stPAReportNo As String, stGAReportNo As String, stCoNo As String, stReportPath As String

                  Dim stModelPath As String, stPAModel As String, stGAModel As String, stExportPath As String

                  Dim TempFile As String, stReportDate As String, stGASuspense As String, stGASuspPath As String

                  Dim stExportName As String

                  Dim OpenFile As Boolean, OpenMod As Boolean, ExportFile As Boolean

                  Dim stTransferFilter As String, stGASuspFilter As String, t As Boolean, ServerOn As Integer

                  Dim lngReportCount As Long

                   

                  On Error GoTo Err_Transfer

                   

                  Set colCoNo = New Collection

                  stPAReportNo = "N030000.000"

                  stGAReportNo = "N188000.000"

                  stPAModel = "TransferPA.xmod"

                  stGAModel = "Transfer.xmod"

                  stModelPath = "G:AccountingPRM_ACTGmodelCurrent"

                  stExportName = "Transfer.xls"

                  stExportPath = "G:AccountingPRM_ACTGSW Transfers"

                  TempFile = "C:     empTransfer.txt"

                  stExportPath = stExportPath & stExportName

                  stGASuspense = "GA_Suspense.xls"

                  stGASuspPath = "G:AccountingPRM_ACTGSW GA Suspense"

                  stGASuspPath = stGASuspPath & stGASuspense

                  stTransferFilter = "Transfer"

                  stGASuspFilter = "218007"

                   

                  stReportDate = Format$(myDate, "YYYYMMDD")

                   

                  Range("A1").Select

                   

                  Do While ActiveCell <> ""

                      stCoNo = Format$(ActiveCell, "00")

                      colCoNo.Add Item:=stCoNo

                      ActiveCell.Offset(1).Select

                  Loop

                   

                  ServerOn = IsServerActive()

                  If ServerOn = 0 Then

                      Set MonarchObj = CreateObject("Monarch32")

                  End If

                   

                       

                  stLogFile = "G:AccountingPRM_ACTGLogsMonarchLog" & Format$(myDate, "mm-dd-yyyy") & " SW Transfer log"

                  t = MonarchObj.SetLogFile(stLogFile, True)

                   

                  lngReportCount = 0

                  For Each varCoNo In colCoNo

                      stCoNo = varCoNo

                      stReportPath = "R:" & stCoNo & "" & stReportDate & "" & stPAReportNo

                       

                      OpenFile = MonarchObj.SetReportFile(stReportPath, True)

                      If OpenFile = True Then

                          'Tally number of reports loaded

                          lngReportCount = lngReportCount + 1

                          Application.Wait (Now + TimeValue("0:00:01"))

                      End If

                  Next varCoNo

                  'Make sure at least one report is loaded

                  If lngReportCount > 0 Then

                      OpenMod = MonarchObj.SetModelFile(stModelPath & stPAModel)

                      If OpenMod = True Then

                          MonarchObj.CurrentFilter = stTransferFilter

                          ExportFile = MonarchObj.JetExportTable(stExportPath, "Transfer", 2)

                          Application.Wait (Now + TimeValue("0:00:01"))

                          MonarchObj.CurrentFilter = stGASuspFilter

                          ExportFile = MonarchObj.JetExportTable(stGASuspPath, "GA_Suspense", 2)

                          MonarchObj.CloseAllDocuments

                      End If

                  End If

                   

                  lngReportCount = 0

                  For Each varCoNo In colCoNo

                      stCoNo = varCoNo

                      stReportPath = "R:" & stCoNo & "" & stReportDate & "" & stGAReportNo

                      OpenFile = MonarchObj.SetReportFile(stReportPath, True)

                      If OpenFile = True Then

                          'Tally number of reports loaded

                          lngReportCount = lngReportCount + 1

                          Application.Wait (Now + TimeValue("0:00:01"))

                      End If

                  Next varCoNo

                   

                  'Make sure at least one report is loaded

                  If lngReportCount > 0 Then

                      OpenMod = MonarchObj.SetModelFile(stModelPath & stGAModel)

                      If OpenMod = True Then

                          MonarchObj.CurrentFilter = stTransferFilter

                          ExportFile = MonarchObj.JetExportTable(stExportPath, "Transfer", 2)

                          Application.Wait (Now + TimeValue("0:00:05"))

                          MonarchObj.CurrentFilter = stGASuspFilter

                          ExportFile = MonarchObj.JetExportTable(stGASuspPath, "GA_Suspense", 2)

                          MonarchObj.CloseAllDocuments

                      End If

                  End If

                           

                  'MonarchObj.exit

                  'Set MonarchObj = Nothing

                  Range("E2").ClearContents

                  ActiveWorkbook.Save

                  MonarchObj.Exit

                  Exit Sub

               

              Err_Transfer:

                  Open stLog For Output As #1

                      Write #1, "Error #: " & Err.Number & " - " & Err.Description

                  Close #1

                  Resume Next

              End Sub

               

               

              Function IsServerActive()

               

                  On Error GoTo NoServer

                  If MonarchObj.IsActive > 0 Then

                      IsServerActive = 1

                  End If

                  Exit Function

              NoServer:

                  IsServerActive = 0

                  Exit Function

                   

              End Function

              /font[/quote]PS. I also removed stDay, stMonth and stYear as the line  stReportDate = Format$(myDate, "YYYYMMDD")[/i] accomplishes the same task.

               

              Also, the Error Message Box has been replaced by outputting the Error Number and Description to the  Log File.  This way the routine can continue on with the rest of the program.  You'll just need to check the Log File for any errors.

               

              [size="1"][ April 27, 2007, 06:12 PM: Message edited by: Nick Osdale-Popa ][/size]

              • Server Threw an Exception
                RalphB _

                Thanks Nick, I'll give your suggestion a try. I'll also look into the other scripts to see if there is something I can change to make things work better.

                 

                I have been resorting to shutting down my computer for a couple of minutes and bringing it back up just before I leave at night.  That seems to help somewhat, but I never know if I will have problems and which script will cause it.  It is not every night, but it seems more frequent lately.  These scripts ran flawlessly for over 2 years.

                 

                Also, just to muddy the waters some more, I have, on rare occassions, received error messages like " Application failed to initialize properly (0xc0000034). Click OK to terminate application" and instruction at "0x775618b8" referenced memory at "0x00000420". Memory could not be read". The numbers in "()" and in double quotes varies.  These are rare messages though.  There were other messages, but these are the ones I remember.

                 

                IT has swapped the ram chip on my pc and re-loaded Network version of Monarch 8.02Pro.  I'm beginning to wonder if I need a complete rebuild of my pc.