Atozed Forums

Full Version: How do you guys code your database connection
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
What i trying to do is make connection in servercontroller for connect only when server starts. So far i did it in my forms, actually it was bad every time page render it connects over and over. So i am asking how you guys make connection only 1 time when server starts
Generally its better to use a datamodule/session level connection for users. ie one per session and use connection pooling. A single connection for all sessions will create a bottleneck.
Yes... create your connection in the Usersession.
Hi

I use the DataModule features, works well!

Eric
(05-16-2018, 01:36 PM)kudzu Wrote: [ -> ]Generally its better to use a datamodule/session level connection for users. ie one per session and use connection pooling. A single connection for all sessions will create a bottleneck.

Sir do you have some example Code t show me.Source of Intraweb absence
(05-16-2018, 10:21 AM)morhous Wrote: [ -> ]What i trying to do is make connection in servercontroller for connect only when server starts. So far i did it in my forms, actually it was bad every time page render it connects over and over. So i am asking how you guys make connection only 1 time when server starts

Although you are allowed to connect to anything from ServerController you must have in mind that no form of connection present in your ServerController should be shared among user sessions. Meaning: Do not connect DataSets in other places to that ServerController. The ServerController is a singleton, used (shared) by all your sessions, running in different threads.
So, your ServerController connection should be only used to, for instance, retrieve global options for your application, from the database, or saving an application log (in a thread-safe way, of course).

The best way to do it: Add a TSomeDBConnection to your UserSession and connect if from there. Each user session has a dedicated connection to the Database.