Connection was broken or closed  Topic is solved

Discussions relating to Jiwa 7 plugin development, and the Jiwa 7 API.

Connection was broken or closed

Postby Riyaz » Thu Aug 20, 2020 11:43 am

Hi There

Am getting the attached error and then Jiwa crashes while I'm trying to send an email via the plugin. The error doesnt come up straight away but it takes sometime trying to send the email and then errors and crashes if I say OK. The code chunk is as below

Code: Select all
Private Sub EmailInvoice(ByRef SalesOrderForm As JiwaSalesUI.SalesOrder.SalesOrderEntryForm, candidateReportsToEmail As JiwaApplication.JiwaCollection(Of JiwaApplication.PrintGroup.SalesOrderReports.SalesOrderReport), Optional ByVal ExportFormatType As CrystalDecisions.Shared.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat)      
      Try
'      SalesOrderForm.Save()
        If salesOrderForm.GetAbstractPermission("sales order - email invoices") <> JiwaApplication.Security.UserGroup.AccessLevels.Allow Then
            Throw New System.Exception("You do not have sufficient priveleges to email an invoice.")
        End If

        If salesOrderForm.SalesOrder.SalesOrderReports.Count = 0 Then
            If Microsoft.VisualBasic.Interaction.MsgBox("No sales order reports have been defined." & System.Environment.NewLine & System.Environment.NewLine & "Would you like to set some up now ?", Microsoft.VisualBasic.MsgBoxStyle.YesNo , "No Sales Order Reports Configured") = Microsoft.VisualBasic.MsgBoxResult.Yes Then
                salesOrderForm.PrinterSetup()
            Else
                Throw New JiwaApplication.Exceptions.ClientCancelledException
            End If
        End If

        If candidateReportsToEmail.Count = 0 Then
            Throw New System.Exception("There are no reports that are applicable to this particular invoice.  Are there lines to deliver?")
        End If
        ' load print selection dialog       
      Dim emailReportDialog As JiwaSalesUI.SalesOrder.EmailReport = JiwaApplication.Manager.Instance.DialogFactory.CreateDialog(Of JiwaSalesUI.SalesOrder.EmailReport)(New Object() {candidateReportsToEmail}, SalesOrderForm, "Sales Order Entry")
      emailReportDialog.Visible = False
        emailReportDialog.NameToGiveAttachment = "Your invoice-" & salesOrderForm.SalesOrder.InvoiceNo    '<-  You may want to change this attachment name
        emailReportDialog.EmailTo = GetEmailAddress(salesOrderForm.SalesOrder.Debtor.RecID, "Email Invoice")
      emailReportDialog.CC = GetEmailAddress(salesOrderForm.SalesOrder.Debtor.RecID, "CC Email Invoice")
'      emailReportDialog.BCC = "[email protected]"      
        emailReportDialog.From = Microsoft.VisualBasic.Strings.Chr(34) & Microsoft.VisualBasic.Strings.Replace(JiwaApplication.Manager.Instance.Staff.EmailDisplayName, "@", " ") & Microsoft.VisualBasic.Strings.Chr(34) & " <" & JiwaApplication.Manager.Instance.Staff.EmailAddress & ">"
        emailReportDialog.Subject = "Your invoice - " & salesOrderForm.SalesOrder.OrderNo   '<-  You may want to change the Subject text
        emailReportDialog.SelectedReport = candidateReportsToEmail(1)   '<---   This selects which report to email from the list of CandidateReports passed into the Sub.
         
      emailReportDialog.Message = "Dear customer," & System.Environment.NewLine _
                        & "Please find your invoice attached." & System.Environment.NewLine _
                        & System.Environment.NewLine _
                        & "Sent on Processing Sales Order, " & System.Environment.NewLine _
                        & "The Sales Team"
                        
         If emailReportDialog.ShowDialog(salesOrderForm) = System.Windows.Forms.DialogResult.OK Then
'               salesOrderForm.SalesOrder.Email(emailReportDialog.SelectedReport, emailReportDialog.NameToGiveAttachment, emailReportDialog.From, emailReportDialog.EmailTo, emailReportDialog.RequestReadReceipt, emailReportDialog.Subject, emailReportDialog.CC, emailReportDialog.BCC, emailReportDialog.Message, ExportFormatType)
           End If

         Catch ex As System.Exception
         MessageBox.Show(ex.Message+ex.StackTrace)
      End Try
    End Sub
Attachments
email_error_connection_Was_broken.png
email_error_connection_Was_broken.png (295.99 KiB) Viewed 13926 times
Riyaz
Kohai
Kohai
 
Posts: 254
Joined: Wed Dec 02, 2015 2:05 pm
Topics Solved: 2

Re: Connection was broken or closed

Postby Mike.Sheen » Thu Aug 20, 2020 1:56 pm

That code snippet has the part which sends the email commented out - so that's not being executed. This indicates to me it's the call to SalesOrderForm.Save() throwing the exception. If that is the case, then your problem is as the message reports - you've got a network connection issue.

After looking closer at your message, it's coming from the Email object - but that part doing the sending is commented out... so the code you've provided isn't the code which generated the error.

Without having an accurate representation of code causing your error, it's not possible for me to provide an explanation for the error or how to avoid it.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: Connection was broken or closed

Postby Riyaz » Fri Aug 21, 2020 3:51 pm

Hi Mike

I had commented out that line due to that issue, I have uncommented it and have attached the entire plugin.

This is what happens, when we press the SEND button on the email popup, Jiwa gets struck, left it even for 15 mins and then we had to End Task from Task Manager, and then we get that error. So the main issue is its getting stuck while sending email. The SMTP server, login etc are correct as we can send via the Email button successfully.
Attachments
Plugin Delta - Sales Orders. Print and email after Processed..xml
(42.45 KiB) Downloaded 690 times
Riyaz
Kohai
Kohai
 
Posts: 254
Joined: Wed Dec 02, 2015 2:05 pm
Topics Solved: 2

Re: Connection was broken or closed

Postby Riyaz » Tue Aug 25, 2020 12:52 pm

Hi Mike

Can you pls kindly advise on this?
Riyaz
Kohai
Kohai
 
Posts: 254
Joined: Wed Dec 02, 2015 2:05 pm
Topics Solved: 2

Re: Connection was broken or closed

Postby Mike.Sheen » Tue Aug 25, 2020 2:18 pm

Riyaz wrote:Hi Mike

Can you pls kindly advise on this?


I can't get to your error - I think I get another one first (well, technically two errors - your plugin depends on a custom stored proc not provided, but I worked around that).

I get an error processing a sales order for a debtor which is Cash Only because line 51 of your plugin is invoking the Save() method of the sales order within the event handler for the Processed event. It's failing because the sales order had not been re-read at that point so the optimistic concurrency control prevents the update of the SO_Main table.

I note non Cash-Only debtors follows a different branch in your code - so I'm testing that now - but I suspect it will be a similar issue.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: Connection was broken or closed  Topic is solved

Postby Mike.Sheen » Tue Aug 25, 2020 3:31 pm

Attached is the plugin with some changes made to prevent the error.

What was happening was Crystal Reports was reporting a broken connection after giving up on reading the data because it was being told to generate the report in the event handler for the ProcessingEnd event - which is whilst there are uncommitted changes to the database, so a blocking scenario was caused.

The first change was to handle the Processed event instead of the ProcessingEnd event - so from this:
Code: Select all
AddHandler salesOrder.ProcessingEnd , AddressOf salesOrder_Processed

To this:
Code: Select all
AddHandler salesOrder.Processed, AddressOf salesOrder_Processed


Because you named your method salesOrder_Processed I think you did intend to handle the Processed event, but ended up choosing the ProcessingEnd event by mistake.

Next was to Read the sales order before trying to email, as emailing causes a save. You had a Read in there for *some* scenarios, but if was wrapped in a condition to only read if the ChangeFlag was set (which would have effectively discarded pending changes and likely not what you want).

So, try the revision attached.

And next time if you do provide a plugin to demonstrate an issue, please make sure if it depends on custom tables or stored procs, that they be provided - or the plugin dependency on them removed.

Ideally we want to be able to import your plugin straight into demo data and be able to repro the issue - the easier you make it for us to help you, the quicker our responses will be!
Attachments
Plugin Delta - Sales Orders. Print and email after Processed - Revision 1.xml
(44.13 KiB) Downloaded 422 times
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 1 guest