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: 164
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.