Constanly Running SQL Sproc

  • I have an Azure DB. As we all know, that means no SQL Agent. I need to have a background task that runs every few minutes to clean up some things. Since I can't setup an Agent job, I was thinking about a sproc with an infinite loop. That does some work every 5 min. (or whatever). The alternative is an Azure web role. That's probably a better solution, but it's also much more expensive.

    Any thoughts on the infinite loop thing? Is there any way to "sleep" in a sproc?

    .

  • Not sure about Azure and what is available or not - but lookup WAITFOR in BOL. That will allow your process to sleep for a time and start up again.

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

  • Perfect, that looks like exactly what I need. The fact that it exists must mean that it's not THAT bad an idea. 🙂

    Thanks!

    .

  • Although, I guess I'm still stuck with the same basic problem. How do I start the sproc? Without a SQL Agent, I don't have a way to kick it off.

    Anybody know of a way to automatically start a sproc at SQL Server startup?

    .

  • According to Books Online, SQL Azure does not support sp_procoption which is what you would use to have an auto-execute SP.

    Perhaps you could have a scheduled task on a local server that runs the stored proc?

    MM



    select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);

  • Forum Etiquette: How to post Reporting Services problems
  • [/url]
  • Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
  • [/url]
  • How to Post Performance Problems - by Gail Shaw
  • [/url]

  • Thanks MM.

    Bit by Azure again. Man, I really need to talk my company off SQL Azure. It is just too limited right now. Anyone out there looking to move to Azure, DON'T DO IT if your app depends on ANYTHING other than DML, DDL. It's just not there yet.

    The local server -> Azure server is a thought. Probably ought to just stick with a basic solution and create a web role I guess. Thanks for the help all!

    .

  • BSavoie (1/2/2011)


    Perfect, that looks like exactly what I need. The fact that it exists must mean that it's not THAT bad an idea. 🙂

    Thanks!

    Just be careful about transactions & locking. A proc running in an infinite loop is going to hold stuff open pretty much infinitely.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • In Microsoft documentation http://msdn.microsoft.com/en-us/library/ee336245.aspx#sqlagent say:

    SQL Server Agent/Jobs

    SQL Azure Database does not support SQL Server Agent or jobs. You can, however, run SQL Server Agent on your on-premise SQL Server and connect to SQL Azure Database.

    Danilo

  • I suppose the on premis SQL Agent is as good as anything. I'm sure I'll find other uses for that scenario anyway. Thanks!

    .

  • If you're looking for background functionality, you should be looking at using an Azure Compute instance to kick this off instead of running it in the storage layer. You have to think of the entire Azure platform as a bunch of separate pieces of functionality that fit together to give you a complete solution.

    Jeremiah Peschka
    Microsoft SQL Server MVP
    Managing Director - Brent Ozar PLF, LLC

  • That's probably where I'll end up going. My issue with that is that I have to spin up a new Azure service who's only job in life is to fire off a TSQL script every 5 mins or so. That's a pretty wasteful resource. I will have other uses for it in the future though, which is why I'm leaning that direction.

    .

  • Viewing 11 posts - 1 through 10 (of 10 total)

    You must be logged in to reply to this topic. Login to reply