How to close a DB connection in Python written using %sql
I am using the %sql
commands in Python to connect to Db2. The connection was established, however .close()
function doesn't work to close such connection. What query can be used to check the status of the connection and close the connection afterwards?
The below code was used to establish the connection.
!pip install --force-reinstall ibm_db==3.1.0 ibm_db_sa==0.3.3
!pip uninstall sqlalchemy==1.4 -y && pip install sqlalchemy==1.3.24
!pip install ipython-sql
%load_ext sql
%sql ibm_db_sa://my-username:my-password@hostname:port/BLUDB?security=SSL
You can list all active connections and close them, see the options for the ipython-sql module.
%sql -l
%sql -x yourSession