[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.sqlserver.programming

Script to kill all user connections to a db except three

paullie69

3/13/2007 10:14:00 AM

Hi guru's

SQL 2000 standard - is there a way of creating a script that will
terminate all user processes to a specific database apart from 3 that
must remain ?

I can find scripts to terminate ALL processes but not specific ones

Please let me know if you need any more information

Thanks in advance for any help

Regards

Paul

7 Answers

Uri Dimant

3/13/2007 10:22:00 AM

0

Did you mean KILL command?





<paullie69@hotmail.com> wrote in message
news:1173780810.415648.8280@v33g2000cwv.googlegroups.com...
> Hi guru's
>
> SQL 2000 standard - is there a way of creating a script that will
> terminate all user processes to a specific database apart from 3 that
> must remain ?
>
> I can find scripts to terminate ALL processes but not specific ones
>
> Please let me know if you need any more information
>
> Thanks in advance for any help
>
> Regards
>
> Paul
>


paullie69

3/13/2007 1:15:00 PM

0

On 13 Mar, 10:22, "Uri Dimant" <u...@iscar.co.il> wrote:
> Did you mean KILL command?
>
> <paulli...@hotmail.com> wrote in message
>
> news:1173780810.415648.8280@v33g2000cwv.googlegroups.com...
>
>
>
> > Hi guru's
>
> > SQL 2000 standard - is there a way of creating a script that will
> > terminate all user processes to a specific database apart from 3 that
> > must remain ?
>
> > I can find scripts to terminate ALL processes but not specific ones
>
> > Please let me know if you need any more information
>
> > Thanks in advance for any help
>
> > Regards
>
> > Paul- Hide quoted text -
>
> - Show quoted text -

Hi

Yes, the kill command but scripted to recursively parse through the
database killing connections excluding 3 specific usernames which must
remain intact,

Cheers

Paul

M Bourgon

3/13/2007 2:31:00 PM

0

On Mar 13, 8:14 am, paulli...@hotmail.com wrote:
> On 13 Mar, 10:22, "Uri Dimant" <u...@iscar.co.il> wrote:
>
>
>
> > Did you mean KILL command?
>
> > <paulli...@hotmail.com> wrote in message
>
> >news:1173780810.415648.8280@v33g2000cwv.googlegroups.com...
>
> > > Hi guru's
>
> > > SQL 2000 standard - is there a way of creating a script that will
> > > terminate all user processes to a specific database apart from 3 that
> > > must remain ?
>
> > > I can find scripts to terminate ALL processes but not specific ones
>
> > > Please let me know if you need any more information
>
> > > Thanks in advance for any help
>
> > > Regards
>
> > > Paul- Hide quoted text -
>
> > - Show quoted text -
>
> Hi
>
> Yes, the kill command but scripted to recursively parse through the
> database killing connections excluding 3 specific usernames which must
> remain intact,
>
> Cheers
>
> Paul



Something like this should do the trick, though let me add the
obligatory BE CAREFUL:
declare @spidlist table (id int identity(1,1), spid int)
declare @spidtokill
declare @start int
declare @end int
insert into @spidlist (spid) select spid from master.dbo.sysprocesses
where loginame is not null or loginame not in ('',
'yoursqlservicesaccount', 'sa', 'your', 'three', 'names')
select @start = min(id) from @spidlist
select @end = max(id) from @spidlist
while @start <= @end
BEGIN
select @spidtokill = spid from @spidlist where id = @start
kill @spid --that may not work directly, in which case just turn it
into a variable and EXEC it
select @spidtokill = NULL --just in case
select @start = @start + 1
END


paullie69

3/13/2007 3:23:00 PM

0

On 13 Mar, 14:30, "M Bourgon" <bour...@gmail.com> wrote:
> On Mar 13, 8:14 am, paulli...@hotmail.com wrote:
>
>
>
>
>
> > On 13 Mar, 10:22, "Uri Dimant" <u...@iscar.co.il> wrote:
>
> > > Did you mean KILL command?
>
> > > <paulli...@hotmail.com> wrote in message
>
> > >news:1173780810.415648.8280@v33g2000cwv.googlegroups.com...
>
> > > > Hi guru's
>
> > > > SQL 2000 standard - is there a way of creating a script that will
> > > > terminate all user processes to a specific database apart from 3 that
> > > > must remain ?
>
> > > > I can find scripts to terminate ALL processes but not specific ones
>
> > > > Please let me know if you need any more information
>
> > > > Thanks in advance for any help
>
> > > > Regards
>
> > > > Paul- Hide quoted text -
>
> > > - Show quoted text -
>
> > Hi
>
> > Yes, the kill command but scripted to recursively parse through the
> > database killing connections excluding 3 specific usernames which must
> > remain intact,
>
> > Cheers
>
> > Paul
>
> Something like this should do the trick, though let me add the
> obligatory BE CAREFUL:
> declare @spidlist table (id int identity(1,1), spid int)
> declare @spidtokill
> declare @start int
> declare @end int
> insert into @spidlist (spid) select spid from master.dbo.sysprocesses
> where loginame is not null or loginame not in ('',
> 'yoursqlservicesaccount', 'sa', 'your', 'three', 'names')
> select @start = min(id) from @spidlist
> select @end = max(id) from @spidlist
> while @start <= @end
> BEGIN
> select @spidtokill = spid from @spidlist where id = @start
> kill @spid --that may not work directly, in which case just turn it
> into a variable and EXEC it
> select @spidtokill = NULL --just in case
> select @start = @start + 1
> END- Hide quoted text -
>
> - Show quoted text -

thanks for the example, I'll give it a try

Much appreciated

Paul

paullie69

3/13/2007 4:10:00 PM

0

On 13 Mar, 15:22, paulli...@hotmail.com wrote:
> On 13 Mar, 14:30, "M Bourgon" <bour...@gmail.com> wrote:
>
>
>
>
>
> > On Mar 13, 8:14 am, paulli...@hotmail.com wrote:
>
> > > On 13 Mar, 10:22, "Uri Dimant" <u...@iscar.co.il> wrote:
>
> > > > Did you mean KILL command?
>
> > > > <paulli...@hotmail.com> wrote in message
>
> > > >news:1173780810.415648.8280@v33g2000cwv.googlegroups.com...
>
> > > > > Hi guru's
>
> > > > > SQL 2000 standard - is there a way of creating a script that will
> > > > > terminate all user processes to a specific database apart from 3 that
> > > > > must remain ?
>
> > > > > I can find scripts to terminate ALL processes but not specific ones
>
> > > > > Please let me know if you need any more information
>
> > > > > Thanks in advance for any help
>
> > > > > Regards
>
> > > > > Paul- Hide quoted text -
>
> > > > - Show quoted text -
>
> > > Hi
>
> > > Yes, the kill command but scripted to recursively parse through the
> > > database killing connections excluding 3 specific usernames which must
> > > remain intact,
>
> > > Cheers
>
> > > Paul
>
> > Something like this should do the trick, though let me add the
> > obligatory BE CAREFUL:
> > declare @spidlist table (id int identity(1,1), spid int)
> > declare @spidtokill
> > declare @start int
> > declare @end int
> > insert into @spidlist (spid) select spid from master.dbo.sysprocesses
> > where loginame is not null or loginame not in ('',
> > 'yoursqlservicesaccount', 'sa', 'your', 'three', 'names')
> > select @start = min(id) from @spidlist
> > select @end = max(id) from @spidlist
> > while @start <= @end
> > BEGIN
> > select @spidtokill = spid from @spidlist where id = @start
> > kill @spid --that may not work directly, in which case just turn it
> > into a variable and EXEC it
> > select @spidtokill = NULL --just in case
> > select @start = @start + 1
> > END- Hide quoted text -
>
> > - Show quoted text -
>
> thanks for the example, I'll give it a try
>
> Much appreciated
>
> Paul- Hide quoted text -
>
> - Show quoted text -

Hi all

Is there any way of making the above script database specific ? ie)
killing off connections from a particular db ?

Thanks once again

Paul

Tibor Karaszi

3/13/2007 4:20:00 PM

0

> Is there any way of making the above script database specific ? ie)
> killing off connections from a particular db ?

Add a WHERE clause for the dbid column in the below query of the script:

select spid from master.dbo.sysprocesses

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/d...
http://sqlblog.com/blogs/tib...


<paullie69@hotmail.com> wrote in message news:1173802190.767369.19020@8g2000cwh.googlegroups.com...
> On 13 Mar, 15:22, paulli...@hotmail.com wrote:
>> On 13 Mar, 14:30, "M Bourgon" <bour...@gmail.com> wrote:
>>
>>
>>
>>
>>
>> > On Mar 13, 8:14 am, paulli...@hotmail.com wrote:
>>
>> > > On 13 Mar, 10:22, "Uri Dimant" <u...@iscar.co.il> wrote:
>>
>> > > > Did you mean KILL command?
>>
>> > > > <paulli...@hotmail.com> wrote in message
>>
>> > > >news:1173780810.415648.8280@v33g2000cwv.googlegroups.com...
>>
>> > > > > Hi guru's
>>
>> > > > > SQL 2000 standard - is there a way of creating a script that will
>> > > > > terminate all user processes to a specific database apart from 3 that
>> > > > > must remain ?
>>
>> > > > > I can find scripts to terminate ALL processes but not specific ones
>>
>> > > > > Please let me know if you need any more information
>>
>> > > > > Thanks in advance for any help
>>
>> > > > > Regards
>>
>> > > > > Paul- Hide quoted text -
>>
>> > > > - Show quoted text -
>>
>> > > Hi
>>
>> > > Yes, the kill command but scripted to recursively parse through the
>> > > database killing connections excluding 3 specific usernames which must
>> > > remain intact,
>>
>> > > Cheers
>>
>> > > Paul
>>
>> > Something like this should do the trick, though let me add the
>> > obligatory BE CAREFUL:
>> > declare @spidlist table (id int identity(1,1), spid int)
>> > declare @spidtokill
>> > declare @start int
>> > declare @end int
>> > insert into @spidlist (spid) select spid from master.dbo.sysprocesses
>> > where loginame is not null or loginame not in ('',
>> > 'yoursqlservicesaccount', 'sa', 'your', 'three', 'names')
>> > select @start = min(id) from @spidlist
>> > select @end = max(id) from @spidlist
>> > while @start <= @end
>> > BEGIN
>> > select @spidtokill = spid from @spidlist where id = @start
>> > kill @spid --that may not work directly, in which case just turn it
>> > into a variable and EXEC it
>> > select @spidtokill = NULL --just in case
>> > select @start = @start + 1
>> > END- Hide quoted text -
>>
>> > - Show quoted text -
>>
>> thanks for the example, I'll give it a try
>>
>> Much appreciated
>>
>> Paul- Hide quoted text -
>>
>> - Show quoted text -
>
> Hi all
>
> Is there any way of making the above script database specific ? ie)
> killing off connections from a particular db ?
>
> Thanks once again
>
> Paul
>

paullie69

3/14/2007 8:47:00 AM

0

On 13 Mar, 16:20, "Tibor Karaszi"
<tibor_please.no.email_kara...@hotmail.nomail.com> wrote:
> > Is there any way of making the above script database specific ? ie)
> > killing off connections from a particular db ?
>
> Add a WHERE clause for the dbid column in the below query of the script:
>
> select spid from master.dbo.sysprocesses
>
> --
> Tibor Karaszi, SQL Server MVPhttp://www.karaszi.com/sqlserver/default.asphttp://sqlblog.com/blogs/tib...
>
>
>
> <paulli...@hotmail.com> wrote in messagenews:1173802190.767369.19020@8g2000cwh.googlegroups.com...
> > On 13 Mar, 15:22, paulli...@hotmail.com wrote:
> >> On 13 Mar, 14:30, "M Bourgon" <bour...@gmail.com> wrote:
>
> >> > On Mar 13, 8:14 am, paulli...@hotmail.com wrote:
>
> >> > > On 13 Mar, 10:22, "Uri Dimant" <u...@iscar.co.il> wrote:
>
> >> > > > Did you mean KILL command?
>
> >> > > > <paulli...@hotmail.com> wrote in message
>
> >> > > >news:1173780810.415648.8280@v33g2000cwv.googlegroups.com...
>
> >> > > > > Hi guru's
>
> >> > > > > SQL 2000 standard - is there a way of creating a script that will
> >> > > > > terminate all user processes to a specific database apart from 3 that
> >> > > > > must remain ?
>
> >> > > > > I can find scripts to terminate ALL processes but not specific ones
>
> >> > > > > Please let me know if you need any more information
>
> >> > > > > Thanks in advance for any help
>
> >> > > > > Regards
>
> >> > > > > Paul- Hide quoted text -
>
> >> > > > - Show quoted text -
>
> >> > > Hi
>
> >> > > Yes, the kill command but scripted to recursively parse through the
> >> > > database killing connections excluding 3 specific usernames which must
> >> > > remain intact,
>
> >> > > Cheers
>
> >> > > Paul
>
> >> > Something like this should do the trick, though let me add the
> >> > obligatory BE CAREFUL:
> >> > declare @spidlist table (id int identity(1,1), spid int)
> >> > declare @spidtokill
> >> > declare @start int
> >> > declare @end int
> >> > insert into @spidlist (spid) select spid from master.dbo.sysprocesses
> >> > where loginame is not null or loginame not in ('',
> >> > 'yoursqlservicesaccount', 'sa', 'your', 'three', 'names')
> >> > select @start = min(id) from @spidlist
> >> > select @end = max(id) from @spidlist
> >> > while @start <= @end
> >> > BEGIN
> >> > select @spidtokill = spid from @spidlist where id = @start
> >> > kill @spid --that may not work directly, in which case just turn it
> >> > into a variable and EXEC it
> >> > select @spidtokill = NULL --just in case
> >> > select @start = @start + 1
> >> > END- Hide quoted text -
>
> >> > - Show quoted text -
>
> >> thanks for the example, I'll give it a try
>
> >> Much appreciated
>
> >> Paul- Hide quoted text -
>
> >> - Show quoted text -
>
> > Hi all
>
> > Is there any way of making the above script database specific ? ie)
> > killing off connections from a particular db ?
>
> > Thanks once again
>
> > Paul- Hide quoted text -
>
> - Show quoted text -

Thankyou for you help

Regards

Paul