Czasami mamy sytuację gdzie nie możemy zmienić bazy z trybu single_user na multi_user. Jest to spowodowane tym, że baza ta jest „trzymana” przez inny proces.
Uzyskujemy wtedy komunikat:
Msg 5064, Level 16, State 1, Line 1
Changes to the state or options of database ‘jira_db’ cannot be made at this time.
The database is in single-user mode, and a user is currently connected to it.
Msg 5069, Level 16, State 1, Line 1 ALTER DATABASE statement failed.
Poniżej skrypt, który to rozwiązuje
03 | DECLARE @tokill varchar (8000) = '' ; |
04 | SELECT @tokill = @tokill + 'kill ' + CONVERT ( varchar (5), spid) + ';' |
05 | FROM master..sysprocesses |
06 | WHERE dbid = db_id( 'jira_db' ) |
11 | alter database [jira_db] set multi_user with rollback immediate; |