Results 1 to 4 of 4

Thread: set single_user with rollback immediate

  1. #1
    Join Date
    Apr 2009
    Posts
    16

    set single_user with rollback immediate

    I working on SQL Server Database & want to set it to single user with rollback so can be restored by me. But the problem with me is that it is hanging up with spid-2. Can any rid me out of this???

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    Re: set single_user with rollback immediate

    KILL spids :

    For disconnecting all the non admin i use the following codes :

    ALTER DATABASE Database1 SET RESTRICTED_USER WITH ROLLBACK IMMEDIATE

    To restore the database. i need to kick developers in which Alter database statement just works on non non admins.

    Code:
    DECLARE @spid varchar(10)
    
    SELECT @spid = spid
    FROM master.sys.sysprocesses
    WHERE dbid IN (DB_ID('Database1'), DB_ID('Database2'))
    
    WHILE @@ROWCOUNT <> 0
    BEGIN
     EXEC('KILL ' + @spid)
    
     SELECT @spid = spid
     FROM master.sys.sysprocesses
     WHERE
      dbid IN (DB_ID('Database1'), DB_ID('Database2')) AND
      spid > @spid
    END
    Normally this script is there with all the SQL Server DBAs. But these is posted to you as you are new to this.

  3. #3
    Join Date
    Apr 2008
    Posts
    1,948

    Re: set single_user with rollback immediate

    To kill the SPID is the process which must be made before the delivery of DBCC CHECKDB the database or d' to carry out the process of restoration. To kill the SPID can be accomplished by adding another stage of your Agent SQL Server or employment in your script \ stored procedure inviting the code below to carry out the process of KILL preliminary to code execution which needs exclusive use of the database.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: set single_user with rollback immediate

    Trying doing this first, but be sure that you need to be amin for applying this code :

    Code:
    GO
    
    ALTER DATABASE <dbname> SET SINGLE_USER WITH ROLLBACK IMMEDIATE
    
    GO

    Also make sure after the restore make it multi user again by following the below code:


    Code:
    GO
    
    ALTER DATABASE <dbname> SET MULTI_USER
    
    GO
    HOPEFULLY YOUR PROBLEM IS SOLVED...!

Similar Threads

  1. Will Rollback Rx works on Windows 7
    By -Deven- in forum Windows Software
    Replies: 3
    Last Post: 05-09-2011, 07:57 PM
  2. Managing Rollback segment in database
    By Adriana_andros in forum Software Development
    Replies: 4
    Last Post: 08-02-2010, 06:48 PM
  3. moviemaker rollback Problem
    By peuda in forum Windows Software
    Replies: 3
    Last Post: 09-05-2009, 05:16 PM
  4. How to rollback previous IE version ?
    By Asaph in forum Technology & Internet
    Replies: 3
    Last Post: 22-04-2009, 11:18 AM
  5. Windows Vista Rollback?
    By Fedlix in forum Vista Setup and Install
    Replies: 3
    Last Post: 23-02-2007, 09:10 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,540,199.35261 seconds with 17 queries