Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 890511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:44:39+00:00 2026-05-15T13:44:39+00:00

I was playing around with a stored procedure and I think I made an

  • 0

I was playing around with a stored procedure and I think I made an endless while loop(I think I forgot to close the cursor)

now it is sending me emails and I don’t know how to stop it. How can I kill it?

edit this is what I see when I do what remus told me to do

Sorry I don’t know how to output the results nicer.

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

Edit 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   

Edit 3

This was the stored procedure

I only had one record in the temp table

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T13:44:39+00:00Added an answer on May 15, 2026 at 1:44 pm

    KILL <spid>; where is the @@SPID of the spinning procedure. Use select * from sys.dm_exec_requests to identify the @@SPID (session_id) if you don’t know it.

    Update

    Yeap, that is an infinite loop. You’re missing a FETCH inside the WHILE loop:

    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 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm playing around with storing application settings in my database, but I think I
I'm playing around with MySQL stored procedures and I need a little help wrapping
I have been playing around with some Python now and start to get a
I'm Playing around in android and right now i added rating bars to a
Playing around with Python - tkInter - Entry widget - when I use validatecommand
Playing around with MongoDB and NoRM in .NET. Thing that confused me - there
Just playing around with Wordpress / Contact Form 7 . Is it possible to
been playing around with ResolveClientUrl(~/Confirmation.aspx) and other methods.. I am tryin go get the
I playing around with the Twitter API for my BlackBerry application. Is there any
After playing around with haskell a bit I stumbled over this function: Prelude Data.Maclaurin>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.