Skip to content

SET SINGLE_USER before dropping the database #700

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 22, 2019
Merged

SET SINGLE_USER before dropping the database #700

merged 1 commit into from
Jun 22, 2019

Conversation

amatsuda
Copy link
Contributor

@amatsuda amatsuda commented Jun 7, 2019

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.

to make sure no other connections are alive
@wpolicarpo wpolicarpo merged commit b6cc40b into rails-sqlserver:master Jun 22, 2019
@amatsuda amatsuda deleted the set_single_user_before_drop branch June 23, 2019 02:11
wpolicarpo added a commit that referenced this pull request Jun 24, 2019
SET SINGLE_USER before dropping the database
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants