Drop all connections

  • I have tried to execute the procedure from Lowel and other procedure where i put all the databases in single user mode. Non of this procedures work in one case...

    I have an app (visual basic app) this app will run the procedure sp_disconnect (from lowel) to disconnect all users from the SQL Server 2005 instance.

    I have made a test, but it does not work as i espected....

    I have a user (SQL Server user) named Pedro that is connected to a dababase through query Window in MS.

    When i execute the procedure to terminate Pedro's connection it does not terminates the connection, because i try to delete Login Pedro but it raises an error...

    Can someone help?

  • ok just to be sure, you did uncomment this line like i said you needed to,right?

    --EXEC SP_EXECUTESQL @STR

    i didn't want other readers running that on production and getting in trouble.

    other than that, you could try a cursor that runs the command alter database @dbname set single_user with rollback immediate on each database:

    USE MASTER

    declare

    @isql varchar(2000),

    @dbname varchar(64)

    declare c1 cursor for select name from master..sysdatabases where name not in ('master','model','msdb','tempdb')

    open c1

    fetch next from c1 into @dbname

    While @@fetch_status <> -1

    begin

    select @isql = 'alter database @dbname set single_user with rollback immediate'

    select @isql = replace(@isql,'@dbname',@dbname)

    print @isql

    exec(@isql)

    fetch next from c1 into @dbname

    end

    close c1

    deallocate c1

    GO

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • river1 (3/30/2010)


    The procedure that Lowel gave me is very usefull but i think that you are right , it's better to put all the databases in to single user mode and then (at the end) set the databases to multi user again.

    Thank you.

    After killing the connections, you can always disable the logins, in lieu of single user mode.

    alter login xyz disable

  • No need steve, i want to delete almost all the logins. But thanks

  • Lowel solution will solve my problem. Thank you

  • river1 (3/31/2010)


    No need steve, i want to delete almost all the logins. But thanks

    But disabling them first will guarantee you'll be able to delete them afterwards.

    Can't logon to the system if your login is disabled. @=)

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

  • Well, you're not disabling your "admin" login; just the user logins. Anyway, the OP doesn't think my suggestion will work.

  • In my case i think that i do not need that, but thanks

Viewing 8 posts - 16 through 22 (of 22 total)

You must be logged in to reply to this topic. Login to reply