Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 no have permission to use the KILL stmt

Author  Topic 

juicyapple
Posting Yak Master

176 Posts

Posted - 2008-04-01 : 09:30:24
I am using the kill statement to terminate a process, and this is done through my VB.net program. But I get the error

User does not have permission to use the KILL statement

This is the store procedure to call for kill statement..Is there any problem to execute it on dinamic sql?


CREATE PROCEDURE Kill_Process
@DBName VARCHAR(100),
@TableName VARCHAR(1000)
AS
SET NOCOUNT ON;
DECLARE @spid smallint;
DECLARE @spid2 smallint;
DECLARE @loginame nchar(128);
DECLARE @nsql NVARCHAR(4000);
SET @loginame = 'xxxx'

EXEC Find_Lock_Info @DBName, @TableName

DECLARE ProcessCursor CURSOR FOR
SELECT spid FROM master.dbo.sysprocesses
WHERE dbid = db_id(@dbname) AND loginame = rtrim(@loginame) AND spid <> @@spid
AND spid IN (SELECT spid FROM dbo.tbl_Lock_Info where dbid = db_id(@DBName) AND OBJECT_NAME(ObjId) = @TableName)


OPEN ProcessCursor;
FETCH NEXT FROM ProcessCursor INTO @spid;
WHILE @@FETCH_STATUS = 0
BEGIN
SET @nsql = 'KILL ' + CONVERT(nvarchar,@spid) + '';
EXEC sp_executesql @nsql;
FETCH NEXT FROM ProcessCursor INTO @spid;
END
CLOSE ProcessCursor;
DEALLOCATE ProcessCursor;
GO


CREATE PROCEDURE Find_Lock_Info
@DBName VARCHAR(100),
@TableName VARCHAR(1000)
AS

SET NOCOUNT ON

BEGIN
CREATE TABLE #tmpLockInfo
(
spid SMALLINT,
dbid SMALLINT,
ObjId INT,
IndId SMALLINT,
Type NCHAR(4),
Resource NCHAR(32),
Mode NVARCHAR(8),
Status NVARCHAR(5)
)

INSERT INTO #tmpLockInfo
(
spid, dbid, ObjId, IndId, Type, Resource, Mode, Status
)
EXEC Lock_Info

TRUNCATE TABLE tbl_Lock_Info

INSERT tbl_Lock_Info
SELECT
spid, dbid, ObjId, Type, Status
FROM #tmpLockInfo WHERE dbid = db_id(@DBName) AND ObjId <> 0 AND OBJECT_NAME(ObjId) = @TableName


END
GO

nr
SQLTeam MVY

12543 Posts

Posted - 2008-04-01 : 10:58:21
You want to give a user permission to use the kill statement?

You could run the proc from a scheduled task as sysadmin in response to the user adding a row to a table - just schedule it to run every minute looking for a row in the table.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

juicyapple
Posting Yak Master

176 Posts

Posted - 2008-04-01 : 11:05:24
I already use the account which has process admin role. I think it is enough as I am able to simply execute this Kill @spid

Just can't find out what's wrong with my store procedure or my vb.net program...

I have one more question. Is that KILL statement has the high priority to kill all the insert/select processes?

quote:
Originally posted by nr

You want to give a user permission to use the kill statement?

You could run the proc from a scheduled task as sysadmin in response to the user adding a row to a table - just schedule it to run every minute looking for a row in the table.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.

Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2008-04-01 : 11:13:29
Check the login that the app is connecting with.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

juicyapple
Posting Yak Master

176 Posts

Posted - 2008-04-01 : 20:43:33
I have checked on it, it is definitely something's wrong with my store procedure.

I tried to execute it in query analyzer, and get this

Server: Msg 6102, Level 14, State 1, Line 1
User does not have permission to use the KILL statement.
Go to Top of Page

juicyapple
Posting Yak Master

176 Posts

Posted - 2008-04-01 : 21:00:11
Problem resolved. The account in live environment does not have process admin role but exist in test server. So I does not aware about this.
Go to Top of Page
   

- Advertisement -