I've just spent several hours troubleshooting a problem with a breakout in 'Receive Inventory', where after calling code from a custom menu (which worked fine), it was no longer possible to email invoices out of the 'Sales Order' form.
When the error condition is triggered, the problem manifests when trying to send an invoice via email. Jiwa.exe goes into la-la land for a few minutes, slowly increasing its memory use until finally it crashes with some variety of out-of-memory error, and the email fails to send. And Jiwa needs to be restarted to be usable again.
By a slow process of trial-and-error (in which testing involved making a change to the breakout, running the custom code, and then opening a sales order and trying to email it out and waiting to see whether or not it crashed), I eventually tracked it down to being something to do with my ADO connection.
My code was using JiwaDatabaseObject.ADOConnection (as suggested by Mike somewhere in this forum), to call a stored procedure to test whether or not a custom menu should be enabled, and it was working perfectly. Since I had all but run out of code to delete after dropping the stored procedure (I was testing my ADO connection error handling code), but was still getting the problem, it came down to a few lines, and the ADO connection itself seemed the most likely target.
I changed my code from doing this:
- Code: Select all
Set con = DB.ADOConnectionObject
to this:
- Code: Select all
Set con = CreateObject("ADODB.Connection")
con.Open DB.ADOConnectionString
and the problem seems to have gone away. I can only assume that calling the stored procedure was somehow leaving the connection in a state that the email code didn't like and wasn't coping with.
For the record, this is a stripped-down, untested version of the problem code. The original has several layers of function call, since I use a function to get an ADO command object for use in several places. Note that I had the problem even when the stored procedure didn't exist, so the name of the sproc is not important, nor the results it would generate if it were valid.
- Code: Select all
Dim con
Set con = JiwaDatabaseObject.ADOConnectionObject
con.CursorLocation = 3 ' adUseClient - make results navigable.
Dim cmd
Set cmd = CreateObject("ADODB.Command")
Set cmd.ActiveConnection = con
cmd.CommandType = 4 ' adCmdStoredProc
cmd.CommandText = "SomeBogusSproc"
cmd.Parameters("@SlipID").Value = SlipID
Set rs = cmd.Execute()
Set rs = Nothing
Set cmd = Nothing
Set con = Nothing
Looking at this code with the benefit of hindsight, I suspect the most likely source of trouble to be changing the cursor mode, since that's the only thing that I change on the connection itself. Although why enabling client-side cursors would break the email, only Mike may be able to answer.
regards,
Ryan