Make sure you are not in this database. Close all query windows that are connected to it, close information about the browser object, close SSMS and open it without the object explorer connected to this server, etc. Run this:
USE [master]; GO ALTER DATABASE mydb SET SINGLE_USER WITH ROLLBACK IMMEDIATE; GO
This should allow you to connect it to the network, then you will run the commands you quoted.
Aaron bertrand
source share