PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
VS 2017 [RESOLVED] Debugging fine on VS 17 but application crashing when executing the .exe-VBForums
Results 1 to 4 of 4

Thread: [RESOLVED] Debugging fine on VS 17 but application crashing when executing the .exe

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2018
    Location
    France, North
    Posts
    61

    Resolved [RESOLVED] Debugging fine on VS 17 but application crashing when executing the .exe

    Hi, let me explain a bit my code purpose before to present my issue.

    I have a .net application which manage procedure forms.
    When the form is not finish after 30 days, I want to notify the user that he need to check this one (A reminder). The notification is a mail notification send thanks to a SMTP Server, the sub procedure works well in others function and I think this is not the problem.

    Here is my code :
    VB.NET Code:
    1. Function Notif_Rappel() As String()
    2.         Dim i%
    3.         Connexion.Open()
    4.         Dim Rq As String = "SELECT * FROM Donnees_MET WHERE Emet <> 'init'"
    5.         Dim Cmd As New SqlCommand(Rq, Connexion)
    6.         Dim Reader As SqlDataReader = Cmd.ExecuteReader()
    7.         Try
    8.             While Reader.Read()
    9.                 'IF THE REQUEST IS OPEN SINCE MORE THAN 30 DAYS
    10.                 If DateDiff(DateInterval.Day, Reader("Date_Demande"), Now) > 30 And Reader("Soldee") Is DBNull.Value Then
    11.                     If Reader("Date_Last_Notif_RespMET") Is DBNull.Value Then GoTo 1
    12.                     'IF A FIRST REMINDER HAS BEEN EXECUTED THEN CHECK THE 30 DAYS BETWEEN TODAY'S AND THE REMINDER'S DATES
    13.                     If DateDiff(DateInterval.Day, Reader("Date_Last_Notif_RespMET"), Now) > 30 And Reader("Soldee") Is DBNull.Value Then
    14. 1:                      ReDim Preserve tab_notif(2, i)
    15.                         tab_notif(0, i) = Reader("Num_MET")
    16.                         tab_notif(1, i) = DateDiff(DateInterval.Day, Reader("Date_Demande"), Now)
    17.                         tab_notif(2, i) = Reader("Resp_MET")
    18.                         i = i + 1
    19.                     End If
    20.                 End If
    21.             End While
    22.         Catch ex As Exception
    23.             MsgBox(ex.Message & " Catégorie d'erreur N° 10")
    24.         Finally
    25.             Cmd.Dispose()
    26.             Connexion.Close()
    27.         End Try
    28.     End Function
    29.  
    30.     Sub Write_Date_Notif()
    31.         'GET AN ARRAY WITH NUMBER, DATE, AND NAME
    32.         Notif_Rappel()
    33.         Dim Rq As String
    34.         For i = 0 To Int((tab_notif.Length - 1) / 3)
    35.             'FOR EACH ELEMENT IN ARRAY THEN SET DATE_Last_Notif WITH THE TODAY'S DATE AND SEND MAIL TO THE USER
    36.             Connexion.Open()
    37.             Rq = "UPDATE Donnees_MET SET Date_Last_Notif_RespMET ='" & Now.ToShortDateString() & "' WHERE Num_MET = '" & tab_notif(0, i) & "'"
    38.             Dim Cmd As New SqlCommand(Rq, Connexion)
    39.             Try
    40.                 Cmd.ExecuteNonQuery()
    41.             Catch ex As Exception
    42.                 MsgBox(ex.Message & " Catégorie d'erreur N° 10")
    43.             Finally
    44.                 Cmd.Dispose()
    45.                 Connexion.Close()
    46.             End Try
    47.             'SENDING MAILS
    48.             Dim sSubject$ = "Rappel, votre MET N° " & Mid(tab_notif(0, i), 1, 2) & "-" & Mid(tab_notif(0, i), 3, 3) & " est toujours en attente !"
    49.             Dim sBody$ = "Bonjour, <br /><br />La MET N° " & Mid(tab_notif(0, i), 1, 2) & "-" & Mid(tab_notif(0, i), 3, 3) & " attend une action de votre part depuis " & tab_notif(1, i) & " jours.<br />Ceci est un rappel.<br /><br />Cordialement."
    50.             Dim sTo(0) As String
    51.             sTo(0) = Mail_Nom(tab_notif(2, i))
    52.             Dim sCC(0) As String
    53.             sCC(0) = ""
    54.             Send_Out(sSubject, sBody, "TEST@123.com", sTo, sCC)
    55.         Next
    56.     End Sub

    Some comments :
    -> First I use the function "Notif_Rappel" to get an array with the number of the procedure form, the name of the responsible and the Date of beginning when 30 days from beginning to taday have passed

    -> Then, in "Write_Date_Notif" I stock in SQL the last date of notification (Today's date) and send a mail to the responsible of the procedure form.

    The issue :

    This code works perfectly fine when I'm in Visual Studio (no debugging issue) nut when I publish it and launch the .exe, I get the following error :

    Name:  Capture error.PNG
Views: 138
Size:  31.7 KB

    Translation : An unhandled exception has occurred in your application. if you click continue, the application will ignore this wander and try to continue. If you click Quit, the application will stop immediately. Object reference not set to an instance of an object.

    Do you have any explanation to that exception ? And how can I have exception with the .exe but nothing in the Visual Studio ? Thank you by advance, Mac.

  2. #2
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,577

    Re: Debugging fine on VS 17 but application crashing when executing the .exe

    In your Notif_Rappel() procedure you only start your try catch block after your execute reader line so any error here would not be trapped, if i were you i would firstly correct this in you Notif_Rappel function like this, so all errors in the procedure are being trapped.


    Code:
    Function Notif_Rappel() As String()
            Dim i%     
            Dim Rq As String = "SELECT * FROM Donnees_MET WHERE Emet <> 'init'"
            Dim Cmd As SqlCommand
            Dim Reader As SqlDataReader
            Try
                Connexion.Open()
                Cmd = New SqlCommand(Rq, Connexion)
                Reader = Cmd.ExecuteReader()
                While Reader.Read()
                    'IF THE REQUEST IS OPEN SINCE MORE THAN 30 DAYS 
                    If DateDiff(DateInterval.Day, Reader("Date_Demande"), Now) > 30 And Reader("Soldee") Is DBNull.Value Then
                        If Reader("Date_Last_Notif_RespMET") Is DBNull.Value Then GoTo 1
                        'IF A FIRST REMINDER HAS BEEN EXECUTED THEN CHECK THE 30 DAYS BETWEEN TODAY'S AND THE REMINDER'S DATES
                        If DateDiff(DateInterval.Day, Reader("Date_Last_Notif_RespMET"), Now) > 30 And Reader("Soldee") Is DBNull.Value Then
    1:                      ReDim Preserve tab_notif(2, i)
                            tab_notif(0, i) = Reader("Num_MET")
                            tab_notif(1, i) = DateDiff(DateInterval.Day, Reader("Date_Demande"), Now)
                            tab_notif(2, i) = Reader("Resp_MET")
                            i = i + 1
                        End If
                    End If
                End While
            Catch ex As Exception
                MsgBox(ex.Message & " Catégorie d'erreur N° 10")
            Finally
                Cmd.Dispose()
                Connexion.Close()
            End Try
        End Function
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2018
    Location
    France, North
    Posts
    61

    Re: Debugging fine on VS 17 but application crashing when executing the .exe

    Thank you for your tip, I finally find what was wrong !

    I wasn't handle the Null case of my array, if the function "Notif_Rappel" do not find any number, the array is nothing and when I test the array.length I get an error of Null.Exception... Perfectly Logic...

    I haven't any exception during debugging because to test it I put some number each time in the array.

    Sorry for bother you with my simple issue finally

    Thanks for your time !

  4. #4

    Thread Starter
    Member
    Join Date
    Aug 2018
    Location
    France, North
    Posts
    61

    Re: Debugging fine on VS 17 but application crashing when executing the .exe

    So I just had this line in "Write_Date_Notif" just before to test the length :

    VB.NET Code:
    1. If tab_notif Is Nothing Then Exit Sub

    Now it works well !

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width