Results 1 to 4 of 4

Thread: Force Detach

  1. #1
    Join Date
    Sep 2005
    Posts
    2

    Force Detach

    Hi

    I need to detach a Database, but with "EXEC sp_detach_db 'test','false'" I can't do this because it is in use.
    Is there a Possibility to make a "force detach" or something?

    Thanks for Help

    Greets

  2. #2
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    kill all the spid that is connecting to your database before executing detach command.

    use something like usp_killprocess

    refer
    http://www.databasejournal.com/featu...le.php/2174031

  3. #3
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    You can use this to kill all sessions in northwind database

    exec master..xp_execresultset
    'select ''kill '' + cast(spid as char) from sysprocesses where db_name(dbid)=
    ''northwind''','master'

  4. #4
    Join Date
    May 2004
    Location
    Dunedin, New Zealand
    Posts
    33
    This code will also work:

    alter database northwind set single_user with rollback immediate
    go

    exec sp_detach_db northwind

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •