Board index » delphi » One TDataBase for each Thread ?

One TDataBase for each Thread ?

Hi,

I made the error to use only one TSession in my MultiThreaded-
Application. I am know about to change this, but one question
came up: Do I also need to create one TDataBase for each
Thread ?

thx a lot,
carsten willems

 

Re:One TDataBase for each Thread ?


Quote
Carsten Willems wrote:

> I made the error to use only one TSession in my MultiThreaded-
> Application. I am know about to change this, but one question
> came up: Do I also need to create one TDataBase for each
> Thread ?

        A TDatabase can be connected to only one TSession at a time.  So given
that each TThread has its own TSession, you must have a separate
TDatabase for each TThread as well.  Otherwise, it would be sharing a
TSession with another TThread, and, as you've found out, that does not
work.

        HTH,

        -Craig

--
Craig Stuntz (TeamB)       Senior Developer, Vertex Systems Corp.
Delphi/InterBase weblog:   http://delphi.weblogs.com
Use Borland servers; posts via others are not seen by TeamB.
For more info, see http://www.borland.com/newsgroups/genl_faqs.html

Re:One TDataBase for each Thread ?


thx a lot

Re:One TDataBase for each Thread ?


another question related to this topic:

is it also necessary / right way to create on TDataBase/TSession for each
Thread when I have a stateless webserver? I thought opening a connection
to a database via odbc takes a lot of time, and when I have 10 threads in
a second, is it also OK to create on DataBase-Connection for each of those?

thank you very much
carsten willems

Re:One TDataBase for each Thread ?


Quote
"Carsten Willems" <cwill...@eoa.de> wrote in message

news:3b4f1f7d_2@dnews...
Quote

> is it also necessary / right way to create on TDataBase/TSession for each
> Thread when I have a stateless webserver? I thought opening a connection
> to a database via odbc takes a lot of time, and when I have 10 threads in
> a second, is it also OK to create on DataBase-Connection for each of

those?

Yes, but you do not need to manually create them. As long as the TDatabase
and TSession are on your web module and the TSession has AutoSessionName
true, then it is taken care of for you.

It can take time to open a connection, depending on the database, but
webmodules can also be cached (pooled). Once a web module is created it can
stay in memory and the next user can use this already connected web module.

--
Wayne Niddery (Logic Fundamentals, Inc.)
RADBooks: http://www.logicfundamentals.com/RADBooks/delphibooks.html
"Bandwagons are like streetcars, there'll be another along in a few
minutes" - Me!

Other Threads