How to use prefect sqlalchemy without `with` state...
# ask-community
a
How to use prefect sqlalchemy without
with
statement? If we want to perform multiple i/o operations to & from database what is the way to do that? What is the recommended way to open the connection at the beginning and close it at the end?
m
We use our own internal code to manage connections to databases using SQLAlchemy and yes: we open the connection per each task. When the data is fetched or exported, the method has try, except, finally transaction that closes the connection each time the method on connection object is executed.
a
Okay. But doesn't it affect performance?
m
In terms of single query or insert? Nope, we only close connection and open new in another task to ensure to not have any zombie sessions. The most limiting aspect are the SQL Servers themselves