1

Am getting this Operational Error, periodically probably when the application is not active or idle for long hours. On refreshing the page it will vanish. Am using mssql pyodbc connection string ( "mssql+pyodbc:///?odbc_connect= ...") in Formhandlers and DbAuth of gramex

How Can I keep the connection alive in gramex?

Screenshot of error

  • Can you please elaborate on your question more? Where do you have this issue? What programming language? What are you trying to achieve? Can you also include your screenshot here? – Nantharupan Jun 09 '21 at 21:23

1 Answers1

3

Add pool_pre_ping and pool_recycle parameters.

  • pool_pre_ping will normally emit SQL equivalent to “SELECT 1” each time a connection is checked out from the pool; if an error is raised that is detected as a “disconnect” situation, the connection will be immediately recycled. Read more
  • pool_recycle prevents the pool from using a particular connection that has passed a certain age. Read more

eg: engine = create_engine(connection_string, encoding='utf-8', pool_pre_ping=True, pool_recycle=3600)

Alternatively, you can add these parameters for FormHandler in gramex.yaml. This is required only for the first FormHandler with the connection string.

kwargs:
 url: ...
 table: ...
 pool_pre_ping: True
 pool_recycle: 60
Niyas
  • 505
  • 1
  • 6
  • 17