DEV Community

taijidude
taijidude

Posted on

Get rid of an MS SQL Server database in SingleUserMode

Yesterday i while trying to run some tests against a database with a copy of our production data the program i was working on was crashing with strange errors. When trying to connect to the database via sql server management studio i was greeted with all kinds of errors. "The database is in single user mode, no connection allowed" and so on... Looked for every possible app that was connected to this database and deactivated it. Waited for the nightly restart of the database server. Still not possible to connect.

While googling i today i found the stored procedure sp_who2 which lists you all the active connections to you databases.

With the command kill you are able to terminate the connection.

Example:

sp_who2
Kill 51

Enter fullscreen mode Exit fullscreen mode

After this i was able to connect again, delete and restore the database. I'm a bit short on time thats why i'm not investigating any further. But if this comes up again i will dig deeper.

Top comments (0)