SET SINGLE_USER before dropping the database #700
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
SQLServer sometimes (actually very often in my experience) fails to drop database with
Cannot drop database [DATABASE_NAME] because it is currently in use.
error in some environments.https://stackoverflow.com/questions/12702524/unable-to-drop-and-create-database-in-sql-server/12702579#12702579
https://dba.stackexchange.com/questions/2387/sql-server-cannot-drop-database-dbname-because-it-is-currently-in-use-but-n/2391#2391
https://www.mytechmantra.com/LearnSQLServer/Drop-Database-in-SQL-Server-by-Killing-Existing-Connections.html
https://serverfault.com/questions/440034/how-to-force-a-drop-of-mssql-server-database
This patch addresses this FAQ pitfall by changing the target DB to be SINGLE_USER mode before dropping, to make sure no other connections are alive.