Board index » delphi » System Illegally Reentered..HELP

System Illegally Reentered..HELP

My database application was working fine...until I added a call to a
function where the TQuery was on the main form (it's an MDI app).
Now, without warning (but reproducable), it triggers an EDBEngineError
"System Illegally Reentered".  I have not yet been able to track
exactly where this exception is being raised.

FYI, my application uses CO400 and Paradox (to store the data
locally).  We move the data using TBatchMove from the AS/400 and store
in local Paradox tables.  Each table is uniquely named so that
shouldn't be the problem (this has been verified as well).  Once the
data has been downloaded, we open the appropriate table with a TQuery.

For the function that's blowing up...I downloaded the data at
application startup.  My lookups against this Paradox table are via a
Parametized query (which I know works).  I've got exception handling
everywhere trying to trap the offending line but no luck.

Anyone else seen this error?  How'd you get around it?

TIA,

Charles

 

Re:System Illegally Reentered..HELP


There seems to be a bug in the VCL which causes this error. See my
post 'Serious BUG in VCL (dbtables.pas)' earlier or contact me
directly: mduerig at eye.ch (replace at with @ and remove spaces)

Michael

Quote
"Charles Stack" <cst...@itw.com> wrote:
>My database application was working fine...until I added a call to a
>function where the TQuery was on the main form (it's an MDI app).
>Now, without warning (but reproducable), it triggers an EDBEngineError
>"System Illegally Reentered".  I have not yet been able to track
>exactly where this exception is being raised.
>FYI, my application uses CO400 and Paradox (to store the data
>locally).  We move the data using TBatchMove from the AS/400 and store
>in local Paradox tables.  Each table is uniquely named so that
>shouldn't be the problem (this has been verified as well).  Once the
>data has been downloaded, we open the appropriate table with a TQuery.
>For the function that's blowing up...I downloaded the data at
>application startup.  My lookups against this Paradox table are via a
>Parametized query (which I know works).  I've got exception handling
>everywhere trying to trap the offending line but no luck.
>Anyone else seen this error?  How'd you get around it?
>TIA,
>Charles

Re:System Illegally Reentered..HELP


Just found your old post.  Have you tried doing the query in a
background thread?  In such a case, it should be possible to allocate
a new session in the thread?

Thoughts?

Charles

mduerig at eye.ch (Michael R. Duerig) wrote in message
<6ps7as$mk...@forums.borland.com>...

Quote

>There seems to be a bug in the VCL which causes this error. See my
>post 'Serious BUG in VCL (dbtables.pas)' earlier or contact me
>directly: mduerig at eye.ch (replace at with @ and remove spaces)

>Michael

>"Charles Stack" <cst...@itw.com> wrote:

>>My database application was working fine...until I added a call to a
>>function where the TQuery was on the main form (it's an MDI app).
>>Now, without warning (but reproducable), it triggers an
EDBEngineError
>>"System Illegally Reentered".  I have not yet been able to track
>>exactly where this exception is being raised.

>>FYI, my application uses CO400 and Paradox (to store the data
>>locally).  We move the data using TBatchMove from the AS/400 and
store
>>in local Paradox tables.  Each table is uniquely named so that
>>shouldn't be the problem (this has been verified as well).  Once the
>>data has been downloaded, we open the appropriate table with a
TQuery.

>>For the function that's blowing up...I downloaded the data at
>>application startup.  My lookups against this Paradox table are via
a
>>Parametized query (which I know works).  I've got exception handling
>>everywhere trying to trap the offending line but no luck.

>>Anyone else seen this error?  How'd you get around it?

>>TIA,

>>Charles

Re:System Illegally Reentered..HELP


Quote
>Just found your old post.  Have you tried doing the query in a
>background thread?  In such a case, it should be possible to allocate
>a new session in the thread?

No, I encountered the bug in a single threaded app. However, the bug I
found isn't about mutliple threads rather does it concern applications
which are using TSession components. (Wether multi-threaded or not)

If you use additional sessions in you applications I can give some
hints which might help you:

If not necessary don't use additional sessions. It's only necessary if
you access your databases from different threads.

If you have to use sessions I found two workarounds which worked for
me:
1. Don't prepare your query. Instead of

if not MyQuery.prepared then
  MyQuery.prepare;
MyQuery.open;

just use MyQuery.open The VCL takes care about preparing anyway so
performance shouldn't be a matter.
The reason for this is that if you explicitly prepare the query the
VCL sometimes executes some BDE API calls in the context of the wrong
session on consecutive calls to MyQuery.open.

2. Explicitly set the correct session:

if not MyQuery.prepared then
  MyQuery.prepare;
DbiSetCurrSession(MySession.Handle);
MyQuery.open

Good luck

Michael

Re:System Illegally Reentered..HELP


This may or may not have anything to do with your problem but I will
mention it anyway.

I have read (? Delphi Help or elsewhere) that an application should call
BDE function DbiInit only once -- which Delphi components do
automatically, user is not supposed to call this function. May be "some
one" in your app is calling this function without telling you!

The error you mention is generated if a second call is made to the above
BDE function.
Following is  from x:\Delphi_n\Doc\BDE.int
-----------------
ErrCode_ReEntered = 7; {System has been illegally re-entered}

Thanks

jay mavi

Re:System Illegally Reentered..HELP


For stubborn multi-threaders I would use something like

procedure SafeOpen(TDS:TDataset);
begin
    EnterCriticalSection(CritSec);
    try
        if TDataSet is TTable then
            Sessions.OpenSession((TDS as TTable).SessionName);
        if TDataSet is TQuery then
            Sessions.OpenSession((TDS as TQuery).SessionName);
        TDS.Open;
    finally
        LeaveCriticalSection(CritSec);
    end;
end;

...

initialization
    InitializeCriticalSection(CritSec);
end;

Thank you Michael for your succesful debugging on this and for your warning!
Applying (roughly) the above fix on my code helped a lot.

--
Florin Vancea (fvancea.ns...@texnet.ro)
(please remove nspam from return mail address)

Re:System Illegally Reentered..HELP


Hello Florin,

Nice to 'meet' you again!
Last weekend I got my copy of D4 and look, Inprise fixed this bug!
First they ensure now that TBDECallback instances are created and
freed in the context of the correct session and 2nd they removed the
registration of cbCancelquery callbacks for TQuery. As a consequence
the event TQuery.OnServerYield has been silently removed.

Michael

On Tue, 4 Aug 1998 14:01:54 +0300, "Florin Vancea"

Quote
<fvancea.ns...@texnet.ro> wrote:
>For stubborn multi-threaders I would use something like

>procedure SafeOpen(TDS:TDataset);
>begin
>    EnterCriticalSection(CritSec);
>    try
>        if TDataSet is TTable then
>            Sessions.OpenSession((TDS as TTable).SessionName);
>        if TDataSet is TQuery then
>            Sessions.OpenSession((TDS as TQuery).SessionName);
>        TDS.Open;
>    finally
>        LeaveCriticalSection(CritSec);
>    end;
>end;

>...

>initialization
>    InitializeCriticalSection(CritSec);
>end;

>Thank you Michael for your succesful debugging on this and for your warning!
>Applying (roughly) the above fix on my code helped a lot.

>--
>Florin Vancea (fvancea.ns...@texnet.ro)
>(please remove nspam from return mail address)

Re:System Illegally Reentered..HELP


Quote
mduerig at eye.ch wrote in message <35c84806.13112...@forums.borland.com>...
>Nice to 'meet' you again!

Glad to 'meet' you, too!

Quote
>Last weekend I got my copy of D4 and look, Inprise fixed this bug!...
>...

Sounds good, but voices from tis newsgroup led me to think that they merely
replaced it with other ones.
I haven't laid my hand on D4 yet, but for now I'm far better off with the
devil I know :-)

Best regards, Florin.

Other Threads