• ramana3327 (5/24/2016)


    Do you mean

    The alter database to restricted mode is failing because some other sysadmin connection is being used that time.

    This is exactly running in step1

    BEGIN

    DECLARE @kill varchar(8000) = '';

    SELECT @kill = @kill + 'kill ' + CONVERT(varchar(5), spid) + ';'

    FROM master..sysprocesses

    WHERE dbid = db_id('TestDB')

    and SPID >50

    and SPID <> @@Spid

    --select @kill

    EXEC(@kill);

    ALTER DATABASE TestDB SET RESTRICTED_USER

    ALTER DATABASE TestDB SET RESTRICTED_USER

    It looks Alter database is running 2 times in sequenece

    Is this causes any issues? But still not understand how it was successful previously

    We still don't have enough information to really explain why you're seeing what you're seeing.

    However, I can definitely suggest that instead of trying to manually kill all the processes in the DB and hope nothing jumps in before you issue the ALTER DATABASE command, just use ALTER DATABASE...WITH ROLLBACK IMMEDIATE instead.

    Cheers!