#1 2020-01-30 10:45:56

radexpol
Member
From: Poland, Krk
Registered: 2019-11-29
Posts: 116

Database connection lost issue

How the mORMot deal with database connection lost. I'm going to use it with MS SQL and set the ORM to async mode. What's happening if I'll cut the cable between ORM machine and database, the OLE DB I'm using does not inform about connection problems.

Offline

#2 2020-01-31 14:53:01

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,258
Website

Re: Database connection lost issue

It will report the problem as an Exception to the ORM, I guess.
Note that there is a ConnectionTimeOutMinutes property available for automatic regular reconnection.

I tried to add automatic reconnection in the SynDB units if needed - as it does already for the TQuery wrapper.
It should work directly with the ORM.
Please check https://synopse.info/fossil/info/6d5a0a2e6b
Feedback is welcome!

Offline

#3 2020-01-31 16:27:05

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,547
Website

Re: Database connection lost issue

@ab - I think re-connection should be on the ORM layer, not on the DB access layer. In case we lost a connection in the middle of the transaction re-connection does not make sense and can broke all business logic in the unexpected way.

In our ORM implementation we check conn.LastErrorWasAboutConnection in the except block of the ORM method execution, and in case exception is about connection - remove all DB connection from the thread pool using TSQLDBConnectionPropertiesThreadSafe.ClearConnectionPool.
User got an error in this case, transaction is rollbacked by DB server. Next ORM request  will try to esteblish a new connection

In any case I ask to set a default for AllowReconnect to false in NewStatementPrepared to prevent possible breaking changes

Last edited by mpv (2020-01-31 16:28:50)

Offline

#4 2020-01-31 16:39:35

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,258
Website

Re: Database connection lost issue

Yes, ReconnectAfterConnectionError is disabled by default, but could be used with SynDB layer.

I will add some exception interception in mORMotDB for the ORM: that's a good idea!

Offline

#5 2020-01-31 21:18:50

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,258
Website

Re: Database connection lost issue

Please try https://synopse.info/fossil/info/6d3c115472

Feedback is welcome!

Offline

Board footer

Powered by FluxBB