How Can we block or stop processes in T-SQL

How Can we block or stop processes in T-SQL

Post by Loui » Wed, 07 Jun 2000 04:00:00



We would like to automatically block or kill other processes using a set
of databases. We want to do this at very infrequent times where the
entire data in these databases are going to be converted.

Unfortunately the connected workstations are widespread and often, the
users do not end the connected applications. So we want to be able to
kill their process in SQL server.

We have tried creating a process which uses the KILL command in T-SQL,
but it will not permit a variable to be used. IE "KILL 10" works but

For operational reasons, we cannot have a manual process (IE The SQL
Enterprise Manager) kill the processes manually. This procedure needs to
be automated.

Does anywone have an Idea of how we can termminate database connections,
or how we can use the KILL command with a variable?

Thank you.

Louis


 
 
 

How Can we block or stop processes in T-SQL

Post by News » Wed, 07 Jun 2000 04:00:00


Create this sp in the master and run it when you want to 'exit' people...

CREATE PROC usp_KillUser

AS
SET NOCOUNT ON
/* Check to make sure DB is valid ???*/



DECLARE c_Users cursor for
 SELECT spid
   FROM master..sysprocesses (NOLOCK)

OPEN c_Users



BEGIN

  BEGIN


  END

END -- WHILE


> We would like to automatically block or kill other processes using a set
> of databases. We want to do this at very infrequent times where the
> entire data in these databases are going to be converted.

> Unfortunately the connected workstations are widespread and often, the
> users do not end the connected applications. So we want to be able to
> kill their process in SQL server.

> We have tried creating a process which uses the KILL command in T-SQL,
> but it will not permit a variable to be used. IE "KILL 10" works but

> For operational reasons, we cannot have a manual process (IE The SQL
> Enterprise Manager) kill the processes manually. This procedure needs to
> be automated.

> Does anywone have an Idea of how we can termminate database connections,
> or how we can use the KILL command with a variable?

> Thank you.

> Louis




 
 
 

How Can we block or stop processes in T-SQL

Post by Pat Phel » Tue, 13 Jun 2000 04:00:00


>We would like to automatically block or kill other processes using a set
>of databases. We want to do this at very infrequent times where the
>entire data in these databases are going to be converted.

>Unfortunately the connected workstations are widespread and often, the
>users do not end the connected applications. So we want to be able to
>kill their process in SQL server.

>We have tried creating a process which uses the KILL command in T-SQL,
>but it will not permit a variable to be used. IE "KILL 10" works but

>For operational reasons, we cannot have a manual process (IE The SQL
>Enterprise Manager) kill the processes manually. This procedure needs to
>be automated.

>Does anywone have an Idea of how we can termminate database connections,
>or how we can use the KILL command with a variable?

I talked with one of the folks from UPS about this at the "Ask the Experts"
night at Tech-Ed last week.  The short answer is to set the DBO ONLY option in
your database, then use a cursor to kill all of the offending users.  The
syntax would look something like:

EXECUTE sp_dboption 'myDb', 'DBO', true
GO


DECLARE zKill CURSOR FOR SELECT
   'KILL ' + Convert(CHAR(4), spid)
   FROM master.dbo.sysprocesses p (NOLOCK)
   WHERE p.dbid = Db_Id('myDb')

OPEN zKill


   BEGIN


   END

CLOSE zKill
DEALLOCATE zKill

Give this a shot if you haven't found a working answer.

-PatP

====================
I detest SPAM, and boycott the SPAMmers.  Send me ads for your competitors!

Please respond via the newsgroups rather than via email.  If you MUST respond
via email, remove ALL of the digits from my email address

 
 
 

1. Process ID 216:1112 owns resources that are blocking processes on Scheduler

                    Hello !

Our Production SQL server stop responding today. The only related error
message I found in the SQL server error log was :
"Process ID 216:1112 owns resources that are blocking processes on Scheduler
0."

We have recently installed SQL 2000 SP 3. I was wondering if anybody
experienced similar problems.

                   Thanks,

2. Updating/Adding data through a view/join

3. Blocked process SQL reconstructed with the Zero Impact Sql Monitor

4. New C++ Tool - Subtleware for C++/SQL

5. Blocked Processes in SQL Server with SINGLE Access 97 Session

6. is_member terribly slow

7. Blocking Process (SQl-Server 6.5)

8. Decimal Point !!

9. how to kill blocking process in the SQL server

10. Huge errors - blocks,17824,1608,OS error 64, lazy writer teminate sql process

11. MS SQL Server Blocks Processes

12. VB and SQL Server Blocked Processes

13. clussvc.exe, lsass.exe take over cpu...sql processing stopped