I have a callback in dash app that connects to SQL DB but it does not close the SPID connections in my activity monitor in SQL Server. So it will just accumlate a ton of connections. It works locally, where I see the connection open and then close a few seconds later but it does not in production. I have it deployed on Azure App Services. Any idea why?
my dash app in production has a app.callback which connects to microsoft sql server.
i have tried connection.close() and engine.dispose() but the SPID connections in my sql server remains open when I expected it to open > get the data via sql query > then close the connection until the next interval is reached for my callback.
It seems to work locally but not when I deploy it into production in my Azure App Services, I see multiple connections and they dont clear until I shut the app down.
My database admins do not want a ton of open connections.
Got it now! Your issue is that the connections are not returned to the pull in AZ App Service, but it does locally.
I imagine this has more to do with your engine setup and/or Azure than the Dash app by itself, so you might have a better chance googling similar errors in Flask applications. Have you tried e.g. to limit the pool_size of the deployed engine?
Maybe someone else can jump in and help you out, but to me it doesn’t seem to be related to Dash… I have a few applications deployed in other services with similar callbacks and I never saw the open connections increase like this…
EDIT: on a second note, there is a chance that interval is short enough to trigger the callback while it is still executing, potentially before the connection was released… Not sure how Dash would handle that. I would try to move the engine init to the global scope of the app (setting up a sensible pool size), create a connection without the dispose and close it in the finally statement.