Skip to content

DOC GH29075 close database connections after creation #42277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion doc/source/user_guide/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5526,13 +5526,23 @@ below and the SQLAlchemy `documentation <https://docs.sqlalchemy.org/en/latest/c
# Create your engine.
engine = create_engine("sqlite:///:memory:")

If you want to manage your own connections you can pass one of those instead:
If you want to manage your own connections you can pass one of those instead. The example below opens a
connection to the database using a Python context manager that automatically closes the connection after
the block has completed.
See the `SQLAlchemy docs <https://docs.sqlalchemy.org/en/latest/core/connections.html#basic-usage>`__
for an explanation of how the database connection is handled.

.. code-block:: python

with engine.connect() as conn, conn.begin():
data = pd.read_sql_table("data", conn)

.. warning::

When you open a connection to a database you are also responsible for closing it.
Side effects of leaving a connection open may include locking the database or
other breaking behaviour.

Writing DataFrames
''''''''''''''''''

Expand Down