Pravin
Pravin

Reputation: 543

Problems in Executing the SP which has while(true) loop in SQL SERVER

I know it is not good way and may have many issues. But can anyone tell what are the problems in executing the SP which has while loop.

CREATE PROC udpParseData
BEGIN
WHILE(true)
BEGIN
    --logic goes here
END
END

EXEC udpParseData

I want to run it like a service. Instead of running a service which check the DB continuously using SQL Dependancy. Any problem with this and also i have a main concern that how to stop the running SP udpParseData. One more option i have is run the same SP in Scheduler JOB. I wanted to know the restrictions and disadvantages of using this.

Upvotes: 2

Views: 269

Answers (1)

Mike Perrenoud
Mike Perrenoud

Reputation: 67898

You don't want to do this - even a Windows service doesn't work like that. A Windows service would leverage a Timer that wakes up on an interval and starts the message pump.

Write the work you want to execute in a stored procedure and then create a Job on the SQL Server that executes that stored procedure, and setup the times you want it to run. The Job takes the place of the Timer in the Windows service.

Upvotes: 1

Related Questions