|
<< Click to Display Table of Contents >> Navigation: Telegram > 2020 > 05 > 17 > Telegram_2020-05-17T23 |
2020-05-17T23:09:41
just use connection pooling, it works brilliantly. everything on the UserSession gets exactly one copy per session
2020-05-17T23:15:51
My question is about protecting access to DB simultaneously by two threads an I am planning to bring in TCriticalSection. My understanding is that connection pooling will create a limited number of connection that will be reused but the potential of more than one thread getting access to DB at the same time still remains
2020-05-17T23:20:09
Aha, I see. I have a few structures that I have in the ServerController that are rarely used - but access to them is protected by a TCriticalSection
2020-05-17T23:27:40
each session is protected from other threads access. There is no way 2 threads will access the same session at the same time.
If you put your DB connection on the UserSession you are safe
2020-05-17T23:28:13
Are you talking about session threads, or other threads that you create on your own?
2020-05-17T23:29:05
you don't need to (and actually should not) add any critical section to protect DB access there
2020-05-17T23:30:09
I see Alex has responded. Loren suggested using pooling if you are worried about too many connections if you use a connection per session. With pooling only one session at a time uses a pooled connection, so still protected.
2020-05-17T23:30:16
If he has 2 or more threads accessing the same DB, then yes. But only if he creates his own threads, which most of the times doesn't make sense
2020-05-17T23:31:13
each session works basically as a separate desktop application. The same rules apply. Except for the ServerController and a few other objects that are shared among the sessions
2020-05-17T23:31:25
That's the only way I could figure it would make any difference, was if he was creating his own threads. You've got it isolated otherwise.