Sqlalchemy close all connection

I am trying to delete my database using sqlalchemy: I am using the following:

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 also create engene as follows:

 sqlalchemy.create_engine(connection_string, poolclass = NullPool) 

But I always get the error message:

Detailed programming Error: (ProgrammingError) ('42000', '[42000] [Microsoft] [SQL Server ODBC driver] [SQL Server] Cannot delete the database "test_db" because it is currently in use. (3702) (SQLExecDirectW ) ')' drop database test_db '()

How can I force ALL connections to be closed?

+4
source share

Source: https://habr.com/ru/post/1494718/


All Articles