on 2022 Feb 28 1:30 PM
Hello all,
we have a Problem concerning one of our Add-On's. We are importing CSV files via our Add-On, which is displayed to the user as an UI within SAP Business One. The User can browse a file and then click "Import" to start the process. During this import process, a progress bar is displayed constantly within B1 to ensure the UI does not go idle. In the background the Add-On gets an already existing user table and adds field values to it.
However, the Add-On loses the connection to the COM_Object and therefore runs into an Error and closes, no matter what we do.
This happens during the import of huge CSV Files (or even at smaller ones with only 1.5k entries).
Does anyone know how to fix this problem?
VB.Net Codesample:
Dim ercd As Integer
Dim erds As String
sr = New StreamReader(strfile, System.Text.Encoding.GetEncoding(1252))
errtotal = False
While sr.EndOfStream = False
Dim ImpRec() As String = sr.ReadLine.Split(",")
oPROGBAR.Text = "Import is running for " & GetNumberOfLines - oPROGBAR.Value & " records"
oPROGBAR.Value += 1
'// Save data in UDT
Dim IMPDATE As String = Trim(ImpRec(0))
Dim IMPID As String = Trim(ImpRec(0))
*Other String elements for the field values*
'// If the id is numeric then execute
If IsNumeric(IMPID) = True Then
'//get last number
UDT = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
UDT.DoQuery("SELECT TOP 1 (CODE + 1) from [dbo].[TABLENAME] ORDER BY CODE DESC")
oOBJECT = oCompany.UserTables.Item("TABLENAME")
oOBJECT.UserFields.Fields.Item("U_DATE").Value = GetDate(IMPDATE)
oObject.UserFields.Fields.Item("U_ID").Value = Trim(IMPID.PadRight(15).Substring(0, 15))
*Adding more field values*
oOBJECT.Add()
'//Possible Solution did not work:
Application.DoEvents()
'//End of possible solution
oCompany.GetLastError(ercd, erds)
If ercd <> 0 Then
SBO_Application.StatusBar.SetText("DI-API-Error during import: " & CStr(ercd) & " " & erds, SAPbouiCOM.BoMessageTime.bmt_Medium, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
errtotal = True
Else
SBO_Application.StatusBar.SetText("Import is running ...", SAPbouiCOM.BoMessageTime.bmt_Medium, SAPbouiCOM.BoStatusBarMessageType.smt_None)
End If
*Do other stuff*
End If
End While
The exact Error Message is:
"Unable to cast COM object of type 'System.__ComObject' to interface type 'SAPbouiCOM.IApplication'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{ID}' failed due to the following error: System call failed. (Exception from HRESULT: 0x80010100 (RPC_E_SYS_CALL_FAILED))."} System.Exception {System.InvalidCastException"
If more code samples or information are needed, I can provide them on demand.
Request clarification before answering.
For everyone researching this problem:
There is a solution for it in the SAP NODE 1506163.
"Workaround
Set the key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows\“USERPostMessageLimit” in regedit. Make this key large enough like 400,000
Or you can use the RemoveWindowsMessage method which is exposed in 8.82 like this:
System.Threading.Thread.Sleep(1000 * 60); //replace with your real working code
SBO_Application.RemoveWindowsMessage(SAPbouiCOM.BoWindowsMessageType.bo_WM_TIMER, true);
This method enables you to deal with extreme scenarios. When an add-on needs to take a long time to process a UI API event, it prevents SAP Business One from processing the Windows message queue."
If you set the key value, make sure to set it to decimal. (worked for us)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
122 | |
10 | |
8 | |
5 | |
4 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.