Skip to content
Advertisement

Database connection broken even with with SQLAlchemy pre-ping

Since I moved my database from a mssql docker container to an azure database as a service my web application( flask) is being disconnected after several minutes.

It is simply solved by a refresh of the page but still, there is an issue here.

The error raised by SQLAlchemy is an Operational Error (https://docs.sqlalchemy.org/en/14/errors.html#error-e3q8)

I tried to implement the pool_pre_ping=True option in the create_engine function the error is not solved.

I think the disconnect is initiated by the database but I do not know if there is an option to change that. (database is SQL Server 12.0)

Advertisement

Answer

As I am using Flask-SQLAlchemy there are configuration parameters to recycle the pool.

I solved my problem by removing the create_engine function.

I simply add SQLALCHEMY_POOL_RECYCLE = 300 to my configuration file.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement