Board index » delphi » What is the "current session"?

What is the "current session"?

The Delphi 6 documentation states that setting TSession.Active to True
makes this session the "current session".  Just what does this mean?
I have a separate thread that uses its own TSession, TDatabase and
TQuery.  Most of the time it works well, but sometimes the thread's
Execute method fails with a "Connection does not exist" error message
when it tries to use these components.   These components are in a
datamodule along with the TDatabase component used by the main thread.
 (For security reasons, both database components are logged in at app
start-up time, so I may not have the luxury of reactivating the
connection when this error occurs.)  Only one instance of the thread
is ever created (when needed), only this thread uses these components,
and it never disconnects the database connection.  Should the thread's
TSession.Active be set to True at design-time?  Should I always set it
to True in the thread when I'm ready to use it?  Can anyone help me on
this?   Thanks much!
 

Re:What is the "current session"?


Quote
Bob Schnatterly wrote:
> The Delphi 6 documentation states that setting TSession.Active to True
> makes this session the "current session".  Just what does this mean?

A "session" is a connection to the BDE, which owns the various table-cursors
that you may open.  It's the umbrella object under which all data access is
made.

Quote
> I have a separate thread that uses its own TSession, TDatabase and
> TQuery.  Most of the time it works well, but sometimes the thread's
> Execute method fails with a "Connection does not exist" error message
> when it tries to use these components.   These components are in a
> datamodule along with the TDatabase component used by the main thread.
>  (For security reasons, both database components are logged in at app
> start-up time, so I may not have the luxury of reactivating the
> connection when this error occurs.)  Only one instance of the thread
> is ever created (when needed), only this thread uses these components,
> and it never disconnects the database connection.  Should the thread's
> TSession.Active be set to True at design-time?  Should I always set it
> to True in the thread when I'm ready to use it?  Can anyone help me on
> this?   Thanks much!

As far as I know, a "session" is owned by a "thread," so if you are working
with the datamodule from both the main-thread and a child thread you could
have problems.  

It is unlikely that you will want to set Active=True at design-time because
of when and where the design-time actions take place.  They happen as the
form-object is created, and that is probably being done by the main thread.  
Various subtle issues like this one come into play when you try to use BDE
and multiple threads.

Re:What is the "current session"?


Thanks for the info on setting Active to True at design-time.  I also
need to know what the "current session" is (i.e., why it matters, when
it comes into play, etc.).  Anyone know?
Quote
Sundial Services <info_...@sundialservices.com> wrote in message <news:v12ajp6o4qvnf6@corp.supernews.com>...
> Bob Schnatterly wrote:
> > The Delphi 6 documentation states that setting TSession.Active to True
> > makes this session the "current session".  Just what does this mean?

> A "session" is a connection to the BDE, which owns the various table-cursors
> that you may open.  It's the umbrella object under which all data access is
> made.

> > I have a separate thread that uses its own TSession, TDatabase and
> > TQuery.  Most of the time it works well, but sometimes the thread's
> > Execute method fails with a "Connection does not exist" error message
> > when it tries to use these components.   These components are in a
> > datamodule along with the TDatabase component used by the main thread.
> >  (For security reasons, both database components are logged in at app
> > start-up time, so I may not have the luxury of reactivating the
> > connection when this error occurs.)  Only one instance of the thread
> > is ever created (when needed), only this thread uses these components,
> > and it never disconnects the database connection.  Should the thread's
> > TSession.Active be set to True at design-time?  Should I always set it
> > to True in the thread when I'm ready to use it?  Can anyone help me on
> > this?   Thanks much!

> As far as I know, a "session" is owned by a "thread," so if you are working
> with the datamodule from both the main-thread and a child thread you could
> have problems.  

> It is unlikely that you will want to set Active=True at design-time because
> of when and where the design-time actions take place.  They happen as the
> form-object is created, and that is probably being done by the main thread.  
> Various subtle issues like this one come into play when you try to use BDE
> and multiple threads.

Other Threads