Home All Groups Group Topic Archive Search About

how to kick all users out of a database

Author
20 Jul 2006 2:14 PM
PamelaFoxcroft
Hi

I am doing log shipping on sql 2000 and want to kick all users out of
the database before applying the backup or the log.

What  I am doing is writing a cursor which will read sysprocesses to
see which users are in the db. I filter on db_id =db_id('pubs')

Then I kill all the spids.

I repeat a second time in case there are any hangers on.

Is there a better way of doing this?

Author
20 Jul 2006 2:29 PM
ML
Yes: look up ALTER DATABASE in Books Online. Look for "SET SINGLE_USER" .


ML

---
http://milambda.blogspot.com/
Are all your drivers up to date? click for free checkup

Author
20 Jul 2006 2:53 PM
PamelaFoxcroft
Thanks ML, but the problem is that I can't do this in the proc I use to
restore the tlog.

Any other ideas?
ML wrote:
Show quoteHide quote
> Yes: look up ALTER DATABASE in Books Online. Look for "SET SINGLE_USER" .
>
>
> ML
>
> ---
> http://milambda.blogspot.com/
Author
20 Jul 2006 2:56 PM
PamelaFoxcroft
It works!  Thanks ML!
PamelaFoxcr***@gmail.com wrote:
Show quoteHide quote
> Thanks ML, but the problem is that I can't do this in the proc I use to
> restore the tlog.
>
> Any other ideas?
> ML wrote:
> > Yes: look up ALTER DATABASE in Books Online. Look for "SET SINGLE_USER" .
> >
> >
> > ML
> >
> > ---
> > http://milambda.blogspot.com/



Post Thread options