How do I find out that another user locked the table without a runtime error.
When I write rec.Locktable(False) -> runtime error.
When I write rec.Locktable(true) -> the client wait and wait and wait until the othe finishes, but i want something else. I want to react when the table is locked.
0
Comments
Create a codeunit ("Try To Lock A Table") with as parameter the object table.
In the OnRun of the codeunit:
CASE rec.ID OF
3: rec3.LOCKTABLE(FALSE);
36: rec36.LOCKTABLE(FALSE);
37: rec37.LOCKTABLE(FALSE);
END;
// you can also use RecordReference here.
// Like you said : if it is locked, LOCKTABLE(FALSE) will generate an error
to test if the table is locked, do this:
recObject.ID := DATABASE::"Table To Be Locked";
IF CODEUNIT.RUN(CODEUNIT::"Try To Lock A Table",recObject) THEN BEGIN
// Table is not locked
ENDELSE BEGIN
// Table is locked
END;
// the "IF CODEUNIT.RUN(" will intercept errors generated in the codeunit and return FALSE in that case.
// IMPORTANT : any writes to the DB in the codeunit BEFORE the error, will NOT be undone by the error!!!!
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
I believe there is a problem with your suggestion.
Whenever you code then the following conditions apply
- A write trx may not be open before the statement, and
- An implicit COMMIT occurs before the next statement.
Doesn't the implicit COMMIT release all locks, so you cannot say ?There is only an implicit COMMIT when all action stops and the screen is released so the user can work again, so no problem for this one.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
A) A write trx may not be open before the statement: I cite two sources:
1) C/SIDE Reference Guide (on-line help), topic titled 'Codeunit.RUN' contains the following snip:
2) Fin.ext contains the following error string:
An implicit COMMIT occurs before the next statement: Again two sources:
1) C/SIDE Reference Guide, topic titled RUN (Codeunit) contains the following:
2) Think about it: If the construct traps errors, that implies that any trx started in the codeunit is rolled-back. Suppose now that I call a codeunit more than once using the IF construct -- the first time everything goes ok, but the second time an error occurs. If no implicit commit occurs after the first call, then what does the error on the second call roll-back -- the work of the second call only, or both the second call and the first call? If the work of the first call is not implicitly committed, then how can I call the codeunit again (using the IF construct) without committing? Rpt 496 - Batch Post Purchase Orders does just this (forget the actual commit near the end of this codeunit -- consider instead the work done after it in UpdateAnalysisViews, which since v3.70 no longer contain COMMITs).
Years ago, I have something similar in a NAS. To fix it, I wrote a message that arrived in the event-log of Windows and let the NAS crash on the error. Windows restarted the NAS automatically and the NAS retried and in generally after some time also succeeded to do the operation.
I am afraid that there is no way to know if a table is locked. Or you let it crash or you wait.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
Hello.
I have a problem with NAS - it crashed with error, and I need to restart it manually every time. CAn you tell me, please, how you made Windows to restart automatically NAS after error?
About "Test locktable" - I've tried many solutions - and have no success in any. ](*,)
In tab "Recovery" you just have to put in the failure fields : "Restart The Service".
PS I have W2K professional, so if you have another version, it may be a little different.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
Well, I have tested this solution - for me it does not work, because , as I understand, when there are some error in Application server - it comes to Events viewer not with type "error", but with "warning" type. So, in this case W2K does not restart service. How you succeed to made a crash of App service?
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!