Multithreaded FireDac (Concurrent Connections – REST Server) DELPHI


Good morning people,

I would like to ask for your help, if anyone can help I would be super grateful.

The question would be reasonably simple, how to work with Multi Thread in FireDac? In other databases, such as DBISAM, it has a component for Sessions, just configure this component and everything is solved, but firedac does not have this component.

Explaining the case better:

I developed a REST Server in Delphi using DataSnap to export data from a database (Firebird) to mobile devices.

The connection to the database is made by FireDac components. When I start the server I make the connection to the database, the connection is established until the server is closed.

Performing some tests I realized that when a device performs the requests everything works perfectly, but the problem arises when several devices make simultaneous connections , several errors, Access Violation and database errors occur.

To correct these errors, in each method requested on the server I initiate a new connection to the database. By doing this the errors no longer occur and I can connect several devices simultaneously. I know this is not the correct way, I realized right from the start that the process was VERY slow, because every request starts a new connection.

So I would like to know how I work with sessions in FireDac, so that each request on the server does not influence other connections.

Thank you in advance.


For you to work with sessions in DataSnap, you have to create your project from DataSnap Server , because REST technology by default works with LifeCycle Invocation , at each execution of a server method an instance of the class is created and then destroyed, so reason that REST technology will not work.

Creating your project by DataSnap Server , you have the option of LifeCycle Session , and this technology will meet what you need, when the client connects the server maintains an instance of the class per session of the DataSnap.

With the project created, in the ServerContainer1 class, have the DSServerClass component that is responsible for the data cycle, in the LifeCycle property change to Session .

I hope I have clarified your doubt. Anything screams.

Scroll to Top