-
Apr 16th, 2019, 03:16 AM
#1
Thread Starter
Member
[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:
Function Notif_Rappel() As String()
Dim i%
Connexion.Open()
Dim Rq As String = "SELECT * FROM Donnees_MET WHERE Emet <> 'init'"
Dim Cmd As New SqlCommand(Rq, Connexion)
Dim Reader As SqlDataReader = Cmd.ExecuteReader()
Try
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
Sub Write_Date_Notif()
'GET AN ARRAY WITH NUMBER, DATE, AND NAME
Notif_Rappel()
Dim Rq As String
For i = 0 To Int((tab_notif.Length - 1) / 3)
'FOR EACH ELEMENT IN ARRAY THEN SET DATE_Last_Notif WITH THE TODAY'S DATE AND SEND MAIL TO THE USER
Connexion.Open()
Rq = "UPDATE Donnees_MET SET Date_Last_Notif_RespMET ='" & Now.ToShortDateString() & "' WHERE Num_MET = '" & tab_notif(0, i) & "'"
Dim Cmd As New SqlCommand(Rq, Connexion)
Try
Cmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message & " Catégorie d'erreur N° 10")
Finally
Cmd.Dispose()
Connexion.Close()
End Try
'SENDING MAILS
Dim sSubject$ = "Rappel, votre MET N° " & Mid(tab_notif(0, i), 1, 2) & "-" & Mid(tab_notif(0, i), 3, 3) & " est toujours en attente !"
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."
Dim sTo(0) As String
sTo(0) = Mail_Nom(tab_notif(2, i))
Dim sCC(0) As String
sCC(0) = ""
Send_Out(sSubject, sBody, "TEST@123.com", sTo, sCC)
Next
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 :
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.
-
Apr 16th, 2019, 03:36 AM
#2
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
-
Apr 16th, 2019, 03:52 AM
#3
Thread Starter
Member
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 !
-
Apr 16th, 2019, 03:54 AM
#4
Thread Starter
Member
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:
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|