Subject | Connection pooling ??? How to do it??? |
---|---|
Author | Michael L. Horne |
Post date | 2002-09-06T22:28:58Z |
Hello,
First a description of what I am attempting to do.
I am writing a small web server, and I need to access
Interbase to supply the information for the various
web pages. I am of course going to use threads to
allow multiple access.
The problem is in how to do something like connection
pooling of the TIB_Connection. So I can have a
connection for each thread but not have the overhead
of creating and connecting each time a page is called.
I scanned the old messages and saw a reference to
"DisconnectToPool". That sounds great, but what does
it actually do?
Sounds like it stores the handle and next time I
try to connect it reuses the handle (if available) or
creates a new one if not. This sounds like it would
be easy to use and much faster than doing a connection
each time. I assume I would still create IB_Sessions
and so forth.
I assume the code in the thread will be something like:
=================================================
vars ibSession:TIB_Session;
ibConnection:TIB_Connection;
begin
ibSession := TIB_Session.Create(nil);
try
ibConnection := TIB_Connection.Create(ibSession);
try
ibConnection.DatabaseName := xFileName;
ibConnection.UserName := xUserName;
ibConnection.Password := xPassword;
ibConnection.Connect;
try
----- Do some processing here -----
finally
ibConnection.DissconnectToPool;
end;
finally
ibConnection.Free;
end;
finally
ibSession.Free;
end;
=================================================
Is this somewhat like I should do it??????
Please feel free to explain and expand.
Thanks
Michael L. Horne
First a description of what I am attempting to do.
I am writing a small web server, and I need to access
Interbase to supply the information for the various
web pages. I am of course going to use threads to
allow multiple access.
The problem is in how to do something like connection
pooling of the TIB_Connection. So I can have a
connection for each thread but not have the overhead
of creating and connecting each time a page is called.
I scanned the old messages and saw a reference to
"DisconnectToPool". That sounds great, but what does
it actually do?
Sounds like it stores the handle and next time I
try to connect it reuses the handle (if available) or
creates a new one if not. This sounds like it would
be easy to use and much faster than doing a connection
each time. I assume I would still create IB_Sessions
and so forth.
I assume the code in the thread will be something like:
=================================================
vars ibSession:TIB_Session;
ibConnection:TIB_Connection;
begin
ibSession := TIB_Session.Create(nil);
try
ibConnection := TIB_Connection.Create(ibSession);
try
ibConnection.DatabaseName := xFileName;
ibConnection.UserName := xUserName;
ibConnection.Password := xPassword;
ibConnection.Connect;
try
----- Do some processing here -----
finally
ibConnection.DissconnectToPool;
end;
finally
ibConnection.Free;
end;
finally
ibSession.Free;
end;
=================================================
Is this somewhat like I should do it??????
Please feel free to explain and expand.
Thanks
Michael L. Horne