Attempted to read or write protected memory

By | July 31, 2020

The use of Sage 300 Advantage API is increasing day by day and there is an ample requirement of the integrations, import, export that uses it. Developers are now making maximum use of Advantage API compared to COMAPI and XAPI for external programs. XAPI requires separate licenses so end user tries to avoid an additional expense which eliminates the use of XAPI. When we create the utility with Advantage API, developer makes use of the classes and methods that are similar to the COMAPI or XAPI as it is handy.

New Stuff: Cannot access database (error=49153) in Sage 300 while accessing the Company

In this blog, we will be looking into an error generated by Sage 300 using Advantage API in C# .Net.

As a developer, we all are aware that CS Query/CS0120 View is most important and faster for reading data from Sage 300 tables. There can be situations where our program fails and it becomes difficult to identify the exact cause of the error by its description. So, debugging process makes it easier to track the line of code that throws an issue(s) if any. One of the reason for an error “Attempted to read or write protected memory. This is often an indication that other memory is corrupt.” is invalid use of “lockRecord” parameter passed to the function Fetch() of View object.

In our example of reading customer data using CS0120 view, we get an error when reading the data from the object whose Fetch() function has already returned true and we are inside our while loop.

While loop error

Below are the exception details displayed in QuickWatch.

Exception details in quickwatch

In order to get the program working and handling the issue, we need to change the lockRecord parameter to false i.e. customers.Fetch(false).

So, this can be helpful when the developer is stuck in the exception and becomes very cumbersome to track the cause. Developer/Programmer can proceed with their further development hassle free.

About Us

Greytrix – a globally recognized and one of the oldest Sage Gold Development Partner is a one-stop solution provider for Sage ERP and Sage CRM organizational needs. Being acknowledged and rewarded for multi-man years of experience, we bring complete end-to-end assistance for your technical consultations, product customizations, data migration, system integrations, third party add-on development and implementation competence.

Greytrix offers unique GUMU™ integrated solutions of  Sage 300 with Sage CRM, Salesforce.com, Dynamics 365 CRM and Magento eCommerce along with Sage 300 Migration from Sage 50 US, Sage 50 CA, Sage PRO, QuickBooks, Sage Business Vision and Sage Business Works. We also offer best-in-class Sage 300 customization and development services and integration services for applications such as POS | WMS | Payroll | Shipping System | Business Intelligence | eCommerce for Sage 300 ERP and for Sage 300c development services we offer, upgrades of older codes and screens to new web screens, latest integrations using sData and web services  to Sage business partners, end users and Sage PSG worldwide. Greytrix offers 20+ addons for Sage 300 to enhance productivity such as GreyMatrixDocument AttachmentDocument NumberingAuto-Bank ReconciliationPurchase Approval SystemThree way PO matchingBill of Lading and VAT for Middle East. The GUMU™ integration for Dynamics 365 CRM – Sage ERP is listed on Microsoft Appsource with easy implementation package.

For more details on Sage 300 and Sage 300c Services, please contact us at accpac@greytrix.com, We will like to hear from you.