sqlalchemy close all connection

python, sqlalchemy

Solution

The current method for closing all connections using the SQLAlchemy sessions api is

from sqlalchemy.orm import close_all_sessions

close_all_sessions()

as `session.close_all()` is deprecated.

Problem

I'm trying to drop my database using sqlalchemy: ``` def dropDb(self, dbName): self.closeConnection() self.selectDb(None) self.execute("drop database %s" % dbName) def closeConnection(self): self._Session.close_all() self._engine.dispose() del self._Session del self._engine ``` I create the engine with: ``` sqlalchemy.create_engine(connection_string, poolclass = NullPool) ``` But I am getting the following error: Detail ProgrammingError: (ProgrammingError) ('42000', '[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot drop database "test_db" because it is currently in use. (3702) (SQLExecDirectW)') 'drop database test_db' () How can I forcibly close ALL connections?

Original source

Related problems