Disconnect active SQL connections from SMO


Is there a way to use SMO to disconnect all active users from a SQL database, so I can perform a database restore?

The question linked to below is similar, but does not discuss the use of SMO.

When restoring a backup, how do I disconnect all active connections?

This link also is a similar question, but remains unanswered:



You can use the KillAllProcesses method.

If you want to check you can use the GetActiveDBConnectionCount method. But you might want to wait a few second for rollbacks and such


Disconnect active SQL connections from SMO by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply