The error message is as follows:
MSG 5064, Level A, State 1, line 1
Changes to the State or options of database ' Test ' cannot is made at this time. The database is in Single-user mode, and a user was currently connected to it.
MSG 5069, Level A, State 1, line 1
ALTER DATABASE statement failed.
Someone also attached to the database, from the following steps to check:
1) through sys.sysprocesses or sys.dm_exec_sessions, or stored procedure sp_who, and then use the KILL command to cut off the session
Select * from where> dbid=db_id ('MyDB ')
SELECT * from sys.dm_exec_sessions WHERE = db_id ('MyDB')
2) If the above still does not work, then check the sys.dm_tran_locks, and then use the KILL command to cut off the session
Select * from where resource_database_id=db_id ('MyDB')
SQL Server->> failed to switch the database from Single_user mode back to Multi_user mode (Error 5064)