In Dynamics AX 4.0 or Dynamics AX 2009 it can happen that a lengthy operation terminates with the following error message in the InfoLog or Windows application event log:

Error executing code: Insufficient memory to run script. 

A typical example that can result in this error message is when you are running the Reverse Engineering Tool of Dynamics AX 4.0 SP1. Another very common situation is when you are trying to process very large AIF messages with several thousand lines within AX or within an application that uses the Business Connector like the AX BizTalk Adapter.

With Dynamics AX 4.0 a new mechanism was introduced to limit the maximum amount of memory that can be allocated by variables (in X++ code) in a session. This maximum amount is set to 4 MB by default. For some operations like large AIF messages (that are stored in memory during processing) this is however not enough and so the operation is terminated when the maximum amount is reached.

The second part of the error message "Insufficient memory to run script." clearly indicates that this buffer was reached.

 

Here is a sample application eventlog entry that describes a similar issue that you may see when transferring a large file from BizTalk Server to AX 2009 using the AX 2009 BizTalk Adapter:

Source:        Microsoft Dynamics AX 2009 adapter
Event ID:      0
Level:         Error
Description:
The adapter is unable to send the following message to Microsoft Dynamics AX:
MessageId: {Guid}
Error: Error executing code: Insufficient memory to run script.
Error executing code:  object not initialized.



(C)\Classes\\submitMessage


--------------------------------------------------------------------------
Product Version : 5.0
Assembly Version : 5.0.0.0
Class  : AdapterTransmitterEndpoint
Method  : ProcessMessage
Subsystem : BizTalkDynamicsAdapter
--------------------------------------------------------------------------

 

Please note:
Don't mix up this setting with the SQL buffer setting "Maximum buffer size" that can be set on the Database Tuning tab of the Dynamics AX Server Configuration Utility. Although both sound similar they are two independant settings!

 

The maximum amount can be controlled by a Registry value, however the Registry value needs to be adjusted for the component that is executing the X++ code, which can be either the Dynamics AX Client or the Dynamics AX Business Connector (also used by the AX BizTalk Adapter) and/or the Dynamics AX AOS service. Locate the the MaxBufferSize value as given in in each of the registry keys below. If you do not find the MaxBufferSize value, add one. The MaxBufferSize value has the String type. Set the value to a number that is larger than the size of the file that you want to upload:

For the Dynamics AX Client the correct Registry value is:

AX 4.0:

   Key name:   [HKEY_CURRENT_USER\Software\Microsoft\Dynamics\4.0\Configuration\(configuration name)]
   Value name: maxbuffersize
   Value type: REG_SZ
   Value:      (Maximum amount of memory in MB or 0 for no limit)

AX 2009:

   Key name:   [HKEY_CURRENT_USER\Software\Microsoft\Dynamics\5.0\Configuration\(configuration name)]
   Value name: maxbuffersize
   Value type: REG_SZ
   Value:      (Maximum amount of memory in MB or 0 for no limit)

 

For the Dynamics AX .Net Business Connector/AX BizTalk Adapter the correct location is:

AX 4.0:

   Key name:   [HKEY_LOCAL_MACHINE\Software\Microsoft\Dynamics\4.0\Configuration\(configuration name)]
   Value name: maxbuffersize
   Value type: REG_SZ
   Value:      (Maximum amount of memory in MB or 0 for no limit)

AX 2009:

   Key name:   [HKEY_LOCAL_MACHINE\Software\Microsoft\Dynamics\5.0\Configuration\(configuration name)]
   Value name: maxbuffersize
   Value type: REG_SZ
   Value:      (Maximum amount of memory in MB or 0 for no limit)

 NOTE: On a couple of occassions we have noticed that setting the MaxBufferSize to 0 (zero) on the BizTalk Server, causes it to raise the following error when transferring files larger than 6Mb:

RPC exception 5 occurred in session x

For the Dynamics AX AOS the correct Registry value is:

AX 4.0:

   Key name:   [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Dynamics Server\4.0\(AOS instance)\(configuration name)]
   Value name: maxbuffersize
   Value type: REG_SZ
   Value:      (Maximum amount of memory in MB or 0 for no limit)

 AX 2009:

   Key name:   [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Dynamics Server\5.0\(AOS instance)\(configuration name)]
   Value name: maxbuffersize
   Value type: REG_SZ
   Value:      (Maximum amount of memory in MB or 0 for no limit)

 

Please note:

  • The Registry value maxbuffersize is of the type REG_SZ (string) and does by default not exist
  • After the Registry value was created or changed the affected component needs to be restarted
  • For some operations that are crossing different tiers it is necessary to adjust the value for all touched tiers
  • Although is is possible to set the value to 0 to completely turn off this limit, this is not recommended!

 

References:

KB961548; KB953914

--author: Daniel Durrer
--editor: Alexander Lachner
--date: 15/06/2009
--last edited by: Anup Shah
--last edited date: 12/Aug/2010