Engineering

Drop MSSQL Database – Currently in Use

By October 1, 2018 No Comments

When using MSSQL server in development, you may need to drop your database to have a migration/init script re-create the whole thing. If you fire off a quick ‘drop database DatabaseNameHere’, you’ll probably encounter an error “Cannot drop database ‘DatabaseNameHere’ because it is currently in use.”

Here’s a command you can execute to stop any active connections and drop the database.

alter database DatabaseNameHere set single_user with rollback immediate;

drop database DatabaseNameHere;