Subject Re: [firebird-support] multithreaded application
Author Helen Borrie
This message probably should have been posted to the IBObjects list,
but I guess your question about arrays is possibly more generic..

At 08:31 AM 25/09/2006, you wrote:


>I have an application with 4 threads that connect to local FB 2.0 RC4
>server. Every one of them uses its own datamodule and TIBODatabase
>component (so creates different session).

That's a wrong assumption. If you do not create a distinct
TIB_Session each time the datamodule is created, all components will
use the autocreated global TIB_Session and you will get corrupt
memory in your threads. In addition, this explicit TIB_Session must
be the first component in the creation order.


>Under heavy load I get 2 kinds of exections:
>1. error -519 "prepare statement identifies a prepare statement with
>and open cursor"

In a non-threaded environment, this error happens when your code
attempts to unprepare and reprepare a statement while records are
still being fetched (or waiting to be fetched) for the current
execution of the statement. However, in your setup, where you have
session-wide references potentially crossing thread boundaries, it's
probably a side effect that will go away when you fix the threading issue.

>2. Message: ISC ERROR CODE:335544727 ISC ERROR MESSAGE: Error
>writing data to the connection. STATEMENT: TIBOInternalDataset:
>"<TApplication>.dmObrobkaThr.DetailsQuery.IBOqrDetailsQuery." .

Means the connection has crashed at the client side, the server side or both.


>I searched internet, interbase and firebird groups an I foud this:
>http://groups.google.pl/group/borland.public.delphi.database.interbaseexpress/browse_frm/thread/eb6ea4712215a98e/c9fa347e2c4c8926?lnk=gst&q=&rnum=1#c9fa347e2c4c8926
>
>I use IBODataset decendant components, so it looks exactly like my
>problem.

That's hard to say, as it's a very old posting (2001). At that time,
Asta was in the process of developing a version of their server that
would work transparently with native IBO. That team found some
interesting bugs in IB 6.0 around that time.

>But I dont exactly understand what "Don't use array column
>definitions in your InterBase database. " means, and does it still is
>true to firebird. Please clarify what shouldn't I use to avoid this
>kind of exception by example.

FWIW, I don't know what it means, either. However, over the years
there has been a temptation by Delphi developers to treat IB/Fb array
types transparently as Pascal arrays. They don't work anything like
Pascal arrays and they are not accessible via DSQL, so Davidson's
advice to avoid designing databases using arrays is good advice. If
you *must* use them, then you'll find that "native" IBO (not the
TIBO-- "TDataset-compatible" - series that you are using) does
provide a certain level of support for reading IB/Fb array slices and
mapping them to Pascal arrays. It's not for the faint-hearted, though.

>1 more thing: the problem is much more often when i use Local
>connection. I read on this group that is sholudn't matter.

It matters. A client using Windows "local" connection - implemented
in IBO as cpLocal - is not thread-safe. If you want to thread
connections from your IBO apps, use Protocol cpTCP_IP, use valid
entries in Server and Path, follow the rules about sessions, remember
to make that explicit IB_Session first in the creation order, and
don't forget to set the IB_Session property of your data access
objects appropriately.

>Please help, I really couldnt find any solution.

Use the IBObjects support list to try to pin down the exact
attributes of your problem.

./heLen