FireDac multithread (Concurrent Connections - REST Server) DELPHI

4

Good morning people,

I would like to ask for your help, if anyone can help, I am very grateful.

The question would be fairly simple, How to work with Multi Thread in FireDac? In other databases, such as DBISAM, you have a Session component, you just have to configure this component and everything is solved, but firedac does not have this component.

Better explaining the case:

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 the FireDac components. When I start the server I connect to the database, the connection is established until the server is closed.

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

To correct these errors, in each method requested on the server start 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 right way, I realized at the outset that the process was VERY slow, because every request started a new connection.

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

Thank you in advance.

    
asked by anonymous 17.02.2017 / 13:10

2 answers

-2

Good morning everyone, Just to inform them, I solved the problem using Pool Connection. Worked perfectly. If something needs help, just give it a try.

    
20.02.2017 / 12:20
2

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

Creating your project with 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 by DataSnap session.

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

I hope I have clarified your doubt. Anything gives a shout.

    
17.02.2017 / 18:28