views:

423

answers:

2

I've been recently applying threads for making queries to a MYSQL database, I use MyDAC for connection to DB, 'cause TMyConnection doesnot let making simultaneously queries per a connection, I create a new connection and a new query object per every thread executing a query, so in certain time could happens that server has several connections per a client. If we consider this scenario for several clients connecting to database, this is would be a problem, I guess. Is there a better solution for using threads in queries?

Thanks in advance

+1  A: 

Use a second tier where you can pool some connections (you can do with datasnap or remobjetcs...) This way you can reuse connections of all of your users and mantain the number of connections in a smaller level.

Francis Lee
Do you know where can I get a sample project for your solution? or, may you tell me about any books where I can get more knowledge about this issue? Thanks
Billiardo Aragorn
Look for Datasnap 2009 in Google, there is tons of information, videos, presentations about it. A sample application can be http://cc.embarcadero.com/Item/26057.For remObjects SDK:http://devcenter.remobjects.com/articles/?id={761A0669-1445-4B5F-908C-6DE3ACC3ABA4}
Francis Lee
A: 

Have a look Cary Jansen article called

Using Semaphores in Delphi, Part 2: The Connection Pool

He goes in to great detail about how to provide thread-safe access to a limited number of database connections

Getting is code to work with MyDac - TMyConnection is trivial.

Charles Faiga