I have a codeunit running under NAS that monitors the G/L Register table. Once a new register appears, the codeunit gathers the G/L entries under that register and sends them to another system via Message Queues.
The backend database is SQL Server 2K
The problem I have is that the codeunit reads uncommitted transactions. What I want is to read the records in the G/L register AFTER they have been committed, i.e. avoid dirty reads.
I read the on-line help on TRANSACTIONTYPE but I don't feel any wiser.
I don't want to change the posting routines if possible. Just somehow tell the codeunit to ignore uncommitted transactions.
Thanks
0
Answers
If you need to do that.
Best is after reading all, do a COMMIT and do your changes. Or if this is not possible : use TRANSACTIONTYPE::UPDATE; But this last can give problems with performance.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
I tried to simulate a large posting (one that would take say a minute to complete) and discovered that the NAS codeunit waits until the posting is committed. After some time it times-out and gererates an error of the form:
Table so..and..so cannot be changed because it is locked by another user.
This kind of error will cause the NAS service to stop.
Isn't there a way to simply ignore uncommitted transactions, instead of waiting until they are committed / rolled-back?
Please note that I am not making any changes to the DB. I just do a find on a table.
This should be the last commited entry no.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
I would consider moving the functionality outside to an ADO connection. Make it so that there is code that is like the following:
Basically, you would pass in the G/L Register that you are monitoring to verify that it is "Committed" to the database. If you have an open transaction that has not been committed, you should not have any records in the recordset (or a timeout will occur because the lock on the last record is prohibiting you from getting the record...which is an exclusive lock).
Somone with more experience with ADO may be able to streamline the commands...but I tested it and it works. The timeout issue (because of an exclusive lock) is the toughest part to get over...but if you're running NAS, it would cause the NAS Server to restart, which should be fine.
Another way that you may be able to get over this would be to get the record, issue a LOCKTABLE in C/AL code, retry to get the record, and if you cannot gain a lock on the register, then it potentially has not been committed to the database.
Good luck!
- Scott
Vice President, Deployment Operations
Symbiant Technologies, Inc.
http://www.symbiantsolutions.com
Hi Scott,
Thanks for the tip.
I have however managed in the meantime to sort it out within C/AL.
The trick is to switch to Snapshot, try to access the record and then switch back to UpdateNoLocks.
My fear was that, if the register was taking too long to commit, the codeunit would error out, but it doesn't. It patiently waits until the posting is complete and the register unlocked.
Thanks again. I'll keep you suggestion in mind for future reference.
I have similar issue. I work with NAV2013 R2 and c.kestas’s solution dosen't work, maybe cause NAV version difference. I also use DotNet object way based on Scott Frappier’s solution and its work:)! But I wonder if really NAV 2013 R2 can't read only committed data without SQL and DotNet tricky way? I also won't wait for unlock table with report properties Transactiontype=Update.
My solution base on:
http://mibuso.com/blogs/ara3n/2011/01/1 ... tc-in-nav/
Objective to read only committed LOG data and send it to outer system by NAS report. I know that NAS will be the one process that modify this table, other processes only insert to LOG table.
Nav, T-SQL.