My 2p about ERP Solutions, Information Worker Solutions and other software products (mainly Microsoft Dynamics AX and Microsoft SharePoint).

26 July 2008

Upper limit for open cursors has been exceeded

by Patrik Luca 0 comments

Tag



Problem description: Upper limit for open cursors has been exceeded


When you are working in Dynamics AX, you receive following error: Upper limit for open cursors has been exceeded (90) - use parameter openCursors or change the X++ code.

Solution: Change the X++ code


An easy solution is to increase the maximum limit of open cursors, which is by default 90. But this often means only a postponement of this error message, as it may come back in future.
In most case you should change the X++ code, especially if the error message is coming from custom development. But one of the problems is how to find the X++ code causing the exceeding of the limit of open cursors (and for sure if you didn't write the X++ code yourself...). To find this, I wrote a class which traces the number of open cursors. To use it, call the class on severeral places in your own X++ code: the class will log the number of open cursors together with the stack. As such, you will get an evolution of the number of open cursors during execution of your own X++ code, which can help you to find the erroneous X++ code.

The class has 3 methods:

method 1: classDeclaration

// Class to count unfreed cursors
// Call this class as in methods where you want to count
// the unfreed cursors at that moment: CountUnfreedCursors::construct().run();
// Make sure c:\windows\temp directory exists on the client running the class
class CountUnfreedCursors
{
}

method 2: run
void run()
{
HeapCheck hc = new HeapCheck('dump.log');
int rowIndex;
Common unfreedCursor;
DictTable dict;
ASCIIIO file = new ASCIIIO("c:\\windows\\temp\\" + date2str(Today(),321,2,0,2,0,4) + "CountUnfreedCursors.log","a");
container filecon;
container stack;
;

file.outFieldDelimiter(";");
file.outRecordDelimiter("\r\n");

stack = xSession::xppCallStack();

hc.firstUnfreedCursor();
rowIndex = 0;
while (hc.moreUnfreedCursors())
{
filecon = connull();
rowIndex++;
unfreedCursor = hc.getUnfreedCursor();
dict = new DictTable (unfreedCursor.TableId);
filecon = conins(filecon,conlen(filecon)+1,conpeek(stack,3));
filecon = conins(filecon,conlen(filecon)+1,conpeek(stack,4));
filecon = conins(filecon,conlen(filecon)+1,date2str(Today(),321,2,1,2,1,4) + " " + time2str(TimeNow(),1,1));
filecon = conins(filecon,conlen(filecon)+1,"Table: " + dict.name());
filecon = conins(filecon,conlen(filecon)+1,"Use count: " + int2str(unfreedCursor.usageCount()));
hc.nextUnfreedCursor();
file.write(filecon);
}

filecon = connull();
filecon = conins(filecon,conlen(filecon)+1,"Unfreed cursors: " + int2str(rowIndex));
file.write(filecon);
file.write("------------------------------------------------------------------------------\r\n");
}


method 3: construct
static CountUnfreedCursors construct()
{
CountUnfreedCursors countUnfreedCursors = new CountUnfreedCursors();
;

return countUnfreedCursors;
}


Other interesting resources about the upper limit for open cursors in Dynamics AX:

Comments 0 comments

Patrik Luca, Ieper, BELGIUM
Feel free to use or spread all of the content on my blog. In return, linking back to my blog would be greatly appreciated. All my posts and articles are provided "AS IS" with no warranties.

Subscribe feeds via e-mail
Subscribe in your preferred RSS reader

Subscribe feeds rss Most Read Entries

Subscribe feeds rss Recent Entries

Categories

Recommended Books


Subscribe feeds rss Recent Comments

This Blog is part of the U Comment I Follow movement in blogosphere. Means the comment field of this blog is made DOFOLLOW. Spam wont be tolerated.

Blog Archive

My Blog List

Followers

Links