• anthony.green (1/30/2013)


    andrew gothard (1/30/2013)


    s it's a DEV box, try running this then retrying

    DECLARE @DBName NVARCHAR(200);

    SET @DBName = '<Enter your db name here>';

    DECLARE @spid INT;

    DECLARE IHateCursors CURSOR FOR

    SELECT

    spid

    FROM

    master.dbo.sysprocesses

    WHERE

    dbid = DB_ID(@DBName) and spid > 50

    UNION

    SELECT DISTINCT

    request_session_id

    FROM

    sys.dm_tran_locks

    WHERE

    resource_database_id = DB_ID(@DBName) AND

    request_session_id > 50;

    OPEN IHateCursors;

    FETCH NEXT FROM IHateCursors

    INTO @spid;

    WHILE @@fetch_status = 0

    BEGIN

    EXEC ('kill ' + @spid);

    FETCH NEXT FROM IHateCursors INTO @spid;

    END

    CLOSE IHateCursors;

    DEALLOCATE IHateCursors;

    Or to do it in 1 line

    ALTER DATABSE ... SET SINGLE_USER WITH ROLLBACK IMMEDIATE;

    Will kill all SPIDS, roll them back and if yur in that database context, leave you with access.

    Good point.

    And with no cursor

    I'm a DBA.
    I'm not paid to solve problems. I'm paid to prevent them.