Firedac multithread (Simultaneous connections - REST server) DELPHI

Asked

Viewed 1,858 times

4

Good morning Personal,

I’d like to request some help from you, in case anyone can help I’m super grateful.

Doubt would be reasonably simple, how to work with Multi Thread in Firedac? In other databases, such as DBISAM, 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 the Firedac components. When I start the server I connect 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, however the problem arises when multiple 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 errors no longer occur and I can connect several devices simultaneously. I know this is not the right way, I realized right at the beginning that the process has become VERY slow, because every request starts a new connection.

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

Grateful from now on.

2 answers

2

For you to work with sessions on Datasnap, you have to create your project from the DataSnap Server, for technology REST by default works with LifeCycle Invocation, every run of a server method an instance of the class is created and then destroyed, for this reason REST it won’t do any good.

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

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

I hope I’ve cleared up your doubt. Something’s a scream.

-2


Good morning to all, Just to inform you, I solved the problem using Pool Connection. It worked perfectly. In case something needs a help just give a tap.

  • friend, post a generic response, it is difficult for people who access the site without account to ask your questions when you ask to contact to take the doubt.

  • Hello, it is possible to post how you used the pool Connection?

  • Hello please post an example of the code so we can locate ourselves

Browser other questions tagged

You are not signed in. Login or sign up in order to post.