我正在玩一个存储过程,我想我做了一个无休止的循环(我想我忘了关闭光标)
现在它正在向我发送电子邮件,我不知道如何阻止它。我怎么能杀了它?
编辑这就是我在做remus告诉我做的事情时所看到的
抱歉,我不知道如何更好地输出结果。
1,0,2010-07-06 17:00:45.637,background,RESOURCE MONITOR,NULL,NULL,NULL,NULL,0,1,NULL,0,NULL,0,SLEEP_TASK,,0,1,0,NULL,0,0,0,0,257,0x04848118,0,0,0,4096,us_english,mdy,7,0,0,0,0,0,0,0,0,2,-1,0,0,0,1,0,0
2,0,2010-07-06 17:00:45.637,background,LAZY WRITER,NULL,NULL,NULL,NULL,0,1,NULL,0,LAZYWRITER_SLEEP,904,LAZYWRITER_SLEEP,,0,1,0,NULL,0,0,0,0,1,0x0072C3E8,0,0,0,4096,us_english,mdy,7,0,0,0,0,0,0,0,0,2,-1,0,0,0,1,0,0
4,0,2010-07-06 17:00:45.637,background,LOCK MONITOR,NULL,NULL,NULL,NULL,0,1,NULL,0,REQUEST_FOR_DEADLOCK_SEARCH,4570,REQUEST_FOR_DEADLOCK_SEARCH,,0,1,0,NULL,0,0,0,0,1,0x0072C4D8,0,0,0,4096,us_english,mdy,7,0,0,0,0,0,0,0,0,2,-1,0,0,0,1,0,0
5,0,2010-07-06 17:00:45.637,background,SIGNAL HANDLER,NULL,NULL,NULL,NULL,1,1,NULL,0,KSOURCE_WAKEUP,12587720,KSOURCE_WAKEUP,,0,1,0,NULL,0,0,0,0,0,0x002582F8,0,0,0,4096,us_english,mdy,7,0,0,0,0,0,0,0,0,2,-1,0,0,0,1,0,0
6,0,2010-07-06 17:00:45.637,sleeping,TASK MANAGER,NULL,NULL,NULL,NULL,1,1,NULL,0,NULL,0,MISCELLANEOUS,,0,1,0,NULL,0,0,0,0,NULL,0x00000000,0,0,0,4096,us_english,mdy,7,0,0,0,0,0,0,0,0,2,-1,0,0,0,1,0,0
7,0,2010-07-06 17:00:45.637,background,TRACE QUEUE TASK,NULL,NULL,NULL,NULL,1,1,NULL,0,SQLTRACE_BUFFER_FLUSH,3213,SQLTRACE_BUFFER_FLUSH,,0,1,0,NULL,0,0,0,0,1,0x0072C7A8,0,0,0,4096,us_english,mdy,7,0,0,0,0,0,0,0,0,2,-1,0,0,0,1,0,0
9,0,2010-07-06 17:00:45.637,background,BRKR TASK,NULL,NULL,NULL,NULL,1,1,NULL,0,BROKER_TRANSMITTER,12588032,BROKER_TRANSMITTER,,0,1,0,NULL,0,0,0,0,1,0x0072CA78,0,0,0,4096,us_english,mdy,7,1,0,1,0,1,1,1,1,2,-1,0,0,0,1,0,0
11,0,2010-07-06 17:00:45.637,background,TASK MANAGER,NULL,NULL,NULL,NULL,1,1,NULL,0,ONDEMAND_TASK_QUEUE,12590216,ONDEMAND_TASK_QUEUE,,0,1,0,NULL,0,0,0,0,0,0x002583E8,0,0,0,4096,us_english,mdy,7,0,0,0,0,0,0,0,0,2,-1,0,0,0,1,0,0
12,0,2010-07-06 17:00:45.637,background,BRKR EVENT HNDLR,NULL,NULL,NULL,NULL,1,1,NULL,0,BROKER_EVENTHANDLER,337289,BROKER_EVENTHANDLER,,0,1,0,NULL,0,0,1170,0,0,0x002586B8,6,43,154502,4096,us_english,mdy,7,1,0,1,0,1,1,1,1,2,-1,0,0,0,1,0,0
13,0,2010-07-06 17:00:45.637,background,BRKR TASK,NULL,NULL,NULL,NULL,1,1,NULL,0,BROKER_TRANSMITTER,12588017,BROKER_TRANSMITTER,,0,1,0,NULL,0,0,0,0,0,0x002585C8,0,0,0,4096,us_english,mdy,7,1,0,1,0,1,1,1,1,2,-1,0,0,0,1,0,0
14,0,2010-07-06 17:00:45.637,sleeping,TASK MANAGER,NULL,NULL,NULL,NULL,1,1,NULL,0,NULL,0,MISCELLANEOUS,,0,1,0,NULL,0,0,0,0,NULL,0x00000000,0,0,1413,4096,us_english,mdy,7,0,0,0,0,0,0,0,0,2,-1,0,0,0,1,0,0
15,0,2010-07-06 17:00:45.637,sleeping,TASK MANAGER,NULL,NULL,NULL,NULL,1,1,NULL,0,NULL,0,MISCELLANEOUS,,0,1,0,NULL,0,0,0,0,NULL,0x00000000,0,101,11396,4096,us_english,mdy,7,0,0,0,0,0,0,0,0,2,-1,0,0,0,1,0,0
16,0,2010-07-06 17:00:45.637,sleeping,TASK MANAGER,NULL,NULL,NULL,NULL,1,1,NULL,0,NULL,0,MISCELLANEOUS,,0,1,0,NULL,0,0,0,0,NULL,0x00000000,0,146,15318,4096,us_english,mdy,7,0,0,0,0,0,0,0,0,2,-1,0,0,0,1,0,0
17,0,2010-07-06 17:00:45.637,sleeping,TASK MANAGER,NULL,NULL,NULL,NULL,1,1,NULL,0,NULL,0,MISCELLANEOUS,,0,1,0,NULL,0,0,0,0,NULL,0x00000000,0,0,235,4096,us_english,mdy,7,0,0,0,0,0,0,0,0,2,-1,0,0,0,1,0,0
18,0,2010-07-06 17:00:45.637,sleeping,TASK MANAGER,NULL,NULL,NULL,NULL,1,1,NULL,0,NULL,0,MISCELLANEOUS,,0,1,0,NULL,0,0,0,0,NULL,0x00000000,0,0,476,4096,us_english,mdy,7,0,0,0,0,0,0,0,0,2,-1,0,0,0,1,0,0
19,0,2010-07-06 17:00:45.637,sleeping,TASK MANAGER,NULL,NULL,NULL,NULL,1,1,NULL,0,NULL,0,MISCELLANEOUS,,0,1,0,NULL,0,0,0,0,NULL,0x00000000,0,0,711,4096,us_english,mdy,7,0,0,0,0,0,0,0,0,2,-1,0,0,0,1,0,0
20,0,2010-07-06 17:00:45.637,sleeping,TASK MANAGER,NULL,NULL,NULL,NULL,1,1,NULL,0,NULL,0,MISCELLANEOUS,,0,1,0,NULL,0,0,0,0,NULL,0x00000000,0,0,506,4096,us_english,mdy,7,0,0,0,0,0,0,0,0,2,-1,0,0,0,1,0,0
21,0,2010-07-06 17:00:45.637,sleeping,TASK MANAGER,NULL,NULL,NULL,NULL,1,1,NULL,0,NULL,0,MISCELLANEOUS,,0,1,0,NULL,0,0,0,0,NULL,0x00000000,0,0,0,4096,us_english,mdy,7,0,0,0,0,0,0,0,0,2,-1,0,0,0,1,0,0
60,0,2010-07-06 20:30:33.360,running,SELECT,0x020000004D4F6005A3E8119F3DD3297095832ABE63E312F2,0,-1,0x060005004D4F6005B801000F000000000000000000000000,5,1,5758612B-D19E-43EB-B9A5-343B30DCA65C,0,NULL,0,MISCELLANEOUS,,0,1,2034480,0x,0,0,0,1,0,0x002595B8,0,0,99,2147483647,us_english,mdy,7,1,1,1,0,1,1,1,1,2,-1,0,19,0,0,0,0
修改2
1 0 2010-07-06 20:38:22.550 background RESOURCE MONITOR NULL NULL NULL NULL 0 1 NULL 0 NULL 0 SLEEP_TASK 0 1 0 NULL 0 0 0 0 257 0x048A8118 0 0 0 4096 us_english mdy 7 0 0 0 0 0 0 0 0 2 -1 0 0 0 1 0 0 NULL NULL NULL NULL NULL
2 0 2010-07-06 20:38:22.550 background LAZY WRITER NULL NULL NULL NULL 0 1 NULL 0 LAZYWRITER_SLEEP 561 LAZYWRITER_SLEEP 0 1 0 NULL 0 0 0 0 1 0x0070C3E8 0 0 0 4096 us_english mdy 7 0 0 0 0 0 0 0 0 2 -1 0 0 0 1 0 0 NULL NULL NULL NULL NULL
4 0 2010-07-06 20:38:22.550 background LOCK MONITOR NULL NULL NULL NULL 0 1 NULL 0 REQUEST_FOR_DEADLOCK_SEARCH 2792 REQUEST_FOR_DEADLOCK_SEARCH 0 1 0 NULL 0 0 0 0 1 0x0070C4D8 0 0 0 4096 us_english mdy 7 0 0 0 0 0 0 0 0 2 -1 0 0 0 1 0 0 NULL NULL NULL NULL NULL
5 0 2010-07-06 20:38:22.550 background SIGNAL HANDLER NULL NULL NULL NULL 1 1 NULL 0 KSOURCE_WAKEUP 282252 KSOURCE_WAKEUP 0 1 0 NULL 0 0 0 0 0 0x004F82F8 0 0 0 4096 us_english mdy 7 0 0 0 0 0 0 0 0 2 -1 0 0 0 1 0 0 NULL NULL NULL NULL NULL
6 0 2010-07-06 20:38:22.550 sleeping TASK MANAGER NULL NULL NULL NULL 1 1 NULL 0 NULL 0 MISCELLANEOUS 0 1 0 NULL 0 0 0 0 NULL 0x00000000 0 0 0 4096 us_english mdy 7 0 0 0 0 0 0 0 0 2 -1 0 0 0 1 0 0 NULL NULL NULL NULL NULL
7 0 2010-07-06 20:38:22.550 background TRACE QUEUE TASK NULL NULL NULL NULL 1 1 NULL 0 SQLTRACE_BUFFER_FLUSH 3088 SQLTRACE_BUFFER_FLUSH 0 1 0 NULL 0 0 0 0 1 0x0070C7A8 0 0 0 4096 us_english mdy 7 0 0 0 0 0 0 0 0 2 -1 0 0 0 1 0 0 NULL NULL NULL NULL NULL
9 0 2010-07-06 20:38:22.550 sleeping TASK MANAGER NULL NULL NULL NULL 1 1 NULL 0 NULL 0 MISCELLANEOUS 0 1 0 NULL 0 0 0 0 NULL 0x00000000 6 7 5360 4096 us_english mdy 7 0 0 0 0 0 0 0 0 2 -1 0 0 0 1 0 0 NULL NULL NULL NULL NULL
10 0 2010-07-06 20:38:22.550 background TASK MANAGER NULL NULL NULL NULL 1 1 NULL 0 ONDEMAND_TASK_QUEUE 286683 ONDEMAND_TASK_QUEUE 0 1 0 NULL 0 0 0 0 0 0x004F83E8 0 0 0 4096 us_english mdy 7 0 0 0 0 0 0 0 0 2 -1 0 0 0 1 0 0 NULL NULL NULL NULL NULL
12 0 2010-07-06 20:38:22.550 background BRKR EVENT HNDLR NULL NULL NULL NULL 1 1 NULL 0 BROKER_EVENTHANDLER 1326 BROKER_EVENTHANDLER 0 1 0 NULL 0 0 1045 0 0 0x004F86B8 6 277 53717 4096 us_english mdy 7 1 0 1 0 1 1 1 1 2 -1 0 0 0 1 0 0 NULL NULL NULL NULL NULL
13 0 2010-07-06 20:38:22.550 sleeping TASK MANAGER NULL NULL NULL NULL 1 1 NULL 0 NULL 0 MISCELLANEOUS 0 1 0 NULL 0 0 0 0 NULL 0x00000000 4 0 2830 4096 us_english mdy 7 0 0 0 0 0 0 0 0 2 -1 0 0 0 1 0 0 NULL NULL NULL NULL NULL
14 0 2010-07-06 20:38:22.550 sleeping TASK MANAGER NULL NULL NULL NULL 1 1 NULL 0 NULL 0 MISCELLANEOUS 0 1 0 NULL 0 0 0 0 NULL 0x00000000 0 0 276 4096 us_english mdy 7 0 0 0 0 0 0 0 0 2 -1 0 0 0 1 0 0 NULL NULL NULL NULL NULL
15 0 2010-07-06 20:38:22.550 sleeping TASK MANAGER NULL NULL NULL NULL 1 1 NULL 0 NULL 0 MISCELLANEOUS 0 1 0 NULL 0 0 0 0 NULL 0x00000000 0 0 4716 4096 us_english mdy 7 0 0 0 0 0 0 0 0 2 -1 0 0 0 1 0 0 NULL NULL NULL NULL NULL
16 0 2010-07-06 20:38:22.550 sleeping TASK MANAGER NULL NULL NULL NULL 1 1 NULL 0 NULL 0 MISCELLANEOUS 0 1 0 NULL 0 0 0 0 NULL 0x00000000 0 0 2346 4096 us_english mdy 7 0 0 0 0 0 0 0 0 2 -1 0 0 0 1 0 0 NULL NULL NULL NULL NULL
17 0 2010-07-06 20:38:22.550 background BRKR TASK NULL NULL NULL NULL 1 1 NULL 0 BROKER_TRANSMITTER 282237 BROKER_TRANSMITTER 0 1 0 NULL 0 0 0 0 0 0x004F8898 0 0 0 4096 us_english mdy 7 1 0 1 0 1 1 1 1 2 -1 0 0 0 1 0 0 NULL NULL NULL NULL NULL
18 0 2010-07-06 20:38:22.550 background BRKR TASK NULL NULL NULL NULL 1 1 NULL 0 BROKER_TRANSMITTER 282237 BROKER_TRANSMITTER 0 1 0 NULL 0 0 0 0 1 0x0070CC58 0 0 0 4096 us_english mdy 7 1 0 1 0 1 1 1 1 2 -1 0 0 0 1 0 0 NULL NULL NULL NULL NULL
19 0 2010-07-06 20:38:22.550 sleeping TASK MANAGER NULL NULL NULL NULL 1 1 NULL 0 NULL 0 MISCELLANEOUS 0 1 0 NULL 0 0 0 0 NULL 0x00000000 0 3 3649 4096 us_english mdy 7 0 0 0 0 0 0 0 0 2 -1 0 0 0 1 0 0 NULL NULL NULL NULL NULL
20 0 2010-07-06 20:38:22.550 sleeping TASK MANAGER NULL NULL NULL NULL 1 1 NULL 0 NULL 0 MISCELLANEOUS 0 1 0 NULL 0 0 0 0 NULL 0x00000000 0 0 804 4096 us_english mdy 7 0 0 0 0 0 0 0 0 2 -1 0 0 0 1 0 0 NULL NULL NULL NULL NULL
55 0 2010-07-06 20:43:04.807 running SELECT 0x02000000C11D0A09F92E04D1EE8FD14B7EC06C01E9266CA8 0 -1 0x06000500C11D0A09B881F207000000000000000000000000 5 1 710FE4B3-5EB3-47FD-839C-81B9CD33E56A 0 NULL 0 MISCELLANEOUS 0 1 85928 0x 0 0 0 4 0 0x004F8988 6 0 66 2147483647 us_english mdy 7 1 1 1 0 1 1 1 1 2 -1 0 18 0 0 0 0 NULL NULL NULL 0
编辑3
这是存储过程
我在临时表中只有一条记录
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[csp_test]
AS
BEGIN
declare @temp2 table (
idx int identity(1,1),
title varchar(max),
body varchar(max))
insert into @temp2 (title, body)
select title, body
from temp
declare @title varchar(max)
declare @body varchar(max)
declare myCursor Cursor for select title, body from @temp2
open myCursor
fetch next from myCursor into @title, @body
while @@fetch_status = 0 begin
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'SqlAlerts',
@recipients = 'myEmail@gmail.com',
@body = 'The stored procedure finished successfully.',
@subject = 'Automated Success Message' ;
end
END
答案 0 :(得分:2)
KILL <spid>;
旋转过程的@@ SPID在哪里。如果您不知道,请使用select * from sys.dm_exec_requests
标识@@ SPID(session_id)。
<强>更新强>
Yeap,这是一个无限循环。你在WHILE循环中缺少一个FETCH:
fetch next from myCursor into @title, @body
while @@fetch_status = 0 begin
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'SqlAlerts',
@recipients = 'myEmail@gmail.com',
@body = 'The stored procedure finished successfully.',
@subject = 'Automated Success Message' ;
// Add this line:
fetch next from myCursor into @title, @body
end
答案 1 :(得分:1)
找到与activity monitor的流氓关系并将其删除。或者,如果是紧急情况,只需回收SQL Server服务。
答案 2 :(得分:0)
我只是循环SQL Server服务,但这是您在再次测试之前修复代码所需要做的事情:
open myCursor
fetch next from myCursor into @title, @body
while @@fetch_status = 0 begin
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'SqlAlerts',
@recipients = 'myEmail@gmail.com',
@body = 'The stored procedure finished successfully.',
@subject = 'Automated Success Message' ;
-- Need another fetch here - you are never attempting to seek to the next row
end
-- need CLOSE myCursor here
-- need DEALLOCATE myCursor here