Best way to realize thread safe DB access

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
DataCool
Posts: 11
Joined: Thu 26 Jan 2012 14:02

Best way to realize thread safe DB access

Post by DataCool » Thu 26 Jan 2012 14:28

Hi everybody,

i'm currently writing on some server application accessed by many clients at the same time.
So i'm searching for the best way to realize thread safe DB access,
after reading and searching here for a while 3 ways are possible in my opinion.

1. One DB Connection for each client
This should work for each supported DB right ?
Where should the uniconnection should be created ?
In the main thread, in the "client-Thread" or both ways are working ?

2. Using one DB-Connection for all clients, but use a transaction
for each client.
But how is it if the DB doesn't support transactions (MySQL MyISAM, oder SQLite) ?

3. Creating a "Connection-Pool", which is granting thread safe access to a pool of db connections


Please let me know if there other solutions or any mistakes in my thoughts.

Which way is the best in general ?
Which way is the best for a high frequented web server ?

Please push me into the right direction,
many thanks in advance,

DataCool

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Fri 27 Jan 2012 10:27

Hello,

From the point of view of thread-safety, the most appropriate way is to create separate connection for each client, moreover, this solution will work for any DB. The place to create the connection depends on the architecture of your application.

Post Reply