View Single Post

   
  #8 (permalink)  
Old 02-29-2008, 07:31 PM
Hugo Kornelis
 
Posts: n/a
Default Re: T-SQL CLOSE Connection to DB

On 28 May 2006 18:46:15 -0700, coosa wrote:

>That might be it; some thing remotly is still in use. Then, is there a
>way to determine which connections are being used


Hi coosa,

EXEC sp_who2;

> and wait for them but
>prevent any new connections?


ALTER DATABASE <dbname> SET SINGLE_USER;

(By _not_ adding the WITH ROLLBACK_IMMEDIATE option, you tell SQL Server
to disallow new connections but wait until existing connections are
broken before setting the DB to single user)

Note that many front-end programs keep their connection open, mostly
being idle while the person on the screen enters data, answers a phone
call or visits the water cooler. If you waiting for those connections to
close, you won't have your DB in single-user state before the office
closes.

--
Hugo Kornelis, SQL Server MVP
Reply With Quote