To connect to an Azure SQL database using SQL Alchemy and pyodbc, the application requires a new session for each request to the database.
To achieve this, the requests can be wrapped into decorators that create and close a new session for each request.
SQL Alchemy provides a scoped session utility that ensures the reuse of existing session objects throughout the application, preventing race conditions.
To connect via Entra ID tokens using managed identity, event handlers can be added to retrieve and add the access token to the connection string.