Atozed Forums
How do you guys code your database connection - Printable Version

+- Atozed Forums (https://www.atozed.com/forums)
+-- Forum: Atozed Software Products (https://www.atozed.com/forums/forum-1.html)
+--- Forum: IntraWeb (https://www.atozed.com/forums/forum-3.html)
+---- Forum: English (https://www.atozed.com/forums/forum-16.html)
+----- Forum: IntraWeb General Discussion (https://www.atozed.com/forums/forum-4.html)
+----- Thread: How do you guys code your database connection (/thread-219.html)



How do you guys code your database connection - morhous - 05-16-2018

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


RE: How do you guys code your database connection - kudzu - 05-16-2018

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.


RE: How do you guys code your database connection - ScottWGast - 05-16-2018

Yes... create your connection in the Usersession.


RE: How do you guys code your database connection - etwoss - 05-16-2018

Hi

I use the DataModule features, works well!

Eric


RE: How do you guys code your database connection - morhous - 05-17-2018

(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


RE: How do you guys code your database connection - Alexandre Machado - 05-17-2018

(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.